开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜