Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm currently attempting to disable a link using the following jQuery selector:

$("a[href$=/sites/abcd/sectors]").removeAttr("href");

The problem is that sometimes the href might not always be lower case on the page. When this happens the selector no longer matches.

Does anyone know how to get around this? Can I change the behaviour this once to ignore case?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
509 views
Welcome To Ask or Share your Answers For Others

1 Answer

I ran into this myself. I switched the logic a bit to allow me to compare it without case. It requires a little more work, but at least it works.

$('a').each(function(i,n) {
    var href = $(n).attr("href");
    href = href.toLowerCase();
    if (href.endsWith('/sites/abcd/sectors'))
        $(n).removeAttr('href');
});

You would have to figure out your own endsWith logic.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...