views:

4173

answers:

2

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?

+4  A: 

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.

EndangeredMassa
Thanks, that worked well. I used a regex for the endsWith. By the way, toLower() should be toLowerCase().
Alex Angas
Ah, thanks. I did this from memory and forgot a chunk. I've updated it.
EndangeredMassa
+2  A: 

jQuery was built to be extended. You can correct it or add your own type of case-insensitive selector.

Rick Strahl: Using jQuery to search Content and creating custom Selector Filters

Josh Stodola
Good point. A custom selector would work here as well.
EndangeredMassa