How do I exclude elements whose ID ends in a certain suffix using jQuery
I have this jQuery function:
$(this).change(function(){
alert('I changed. ID: ' + $(this).attr("id"));
});
I need the alert to fire except when the id name ends in -0
. I think I should be using the 开发者_C百科$=
operator. I cannot figure out how to make it work.
Your selector should use :not()
combined with attribute-ends-with ($=
) look like this:
$(":not([id$='-0'])")
It's better to have something in front of that so it doesn't run against every element, a class or an element tag, etc, like this:
$(".myClass:not([id$='-0'])")
try something like this
$("id:not[id$='-0']");
with an if statement.
精彩评论