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?
jQuery attribute value selectors are generally case-sensitive.
Projects In JavaScript & JQueryjQuery uses CSS selector to select elements using CSS. Let us see an example to return a style property on the first matched element. The css( name ) method returns a style property on the first matched element.
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With