javascript - jQuery select all classes except one ID - Stack Overflow

I need to select all divs of a certain class (jqx-slider) excluding oneID (#str_prg) - something like

I need to select all divs of a certain class (jqx-slider) excluding one ID (#str_prg) - something like:

$("div.jqx-slider :not(#str_prg)").each(function () {
.....
});

What is the correct syntax for that?

Also, would it be faster and more effecient code, if I add a "if" condition inside the loop - like

if($(this).attr('id') ! = "str_prg"){

}

Thanks!

I need to select all divs of a certain class (jqx-slider) excluding one ID (#str_prg) - something like:

$("div.jqx-slider :not(#str_prg)").each(function () {
.....
});

What is the correct syntax for that?

Also, would it be faster and more effecient code, if I add a "if" condition inside the loop - like

if($(this).attr('id') ! = "str_prg"){

}

Thanks!

Share Improve this question asked Feb 26, 2014 at 0:51 user2723490user2723490 2,1004 gold badges28 silver badges37 bronze badges 1
  • the documentation for .not is pretty clear... api.jquery./not-selector – Jorg Commented Feb 26, 2014 at 0:57
Add a ment  | 

3 Answers 3

Reset to default 4

You are using an descendant selector between the class selector and the not selector, which is invalid for your requirement

$("div.jqx-slider:not(#str_prg)")

when you say $("div.jqx-slider :not(#str_prg)") it selects all descendants of elements with class jq-slider except the one with id str_prg

Try to remove an unnecessary space char like this:

$("div.jqx-slider:not(#str_prg)")

Remove the space, as it would cause you to select children, instead of the element itself.

$("div.jqx-slider:not(#str_prg)").each(function() {
    .....
});

For the second part of your question, it would be better to just use the CSS selector instead of a JS loop.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745650208a4638217.html

相关推荐

  • javascript - jQuery select all classes except one ID - Stack Overflow

    I need to select all divs of a certain class (jqx-slider) excluding oneID (#str_prg) - something like

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信