Along with a number of other a class elements, I’ve got a link with the markup
<a class="editLink" href="www.somelink.com"> Edit <\a>
And I want to select every a element using jQuery except those in this editLink class.
So I’ve used a.not(".editLink") for the jQuery selector which works fine. However I noticed that this also works when I do a.not("editLink") and a.not("#editLink")
It’s like the jQuery ignores the CSS passed as part of the not() method argument. The docs suggest it is necessary to pass the id/class CSS but from what I can tell it’s un-necessary.
Can anyone shed any light on this? Am I being stupid or is there some magic happening?
Thanks
Update – Okay I think I made an error with my syntax. I was doing:
$("p, a.not(".editLink")").click()...
When it should have been
$("p, a").not("a.editLink").click()...
So my bad. Interestingly though the original did select all the a element apart from those in the editLink class.
Thanks for your help 🙂
It does require a selector string. It’s just treating
"editLink"as a selector string that represents an element called<editLink>, which clearly your<a>elements are not.So, your code
a.not("editLink")“works”… just not the way you expect it to: instead of filtering out those elements that don’t have a class with that name, it does nothing because none of the<a>elements are<editLink>elements. And, if none of your<a>elements have an ID with that name either, then the same goes fora.not("#editLink").