jQuery选择除此之外的所有元素

时间:2014-05-29 10:20:08

标签: jquery

我想选择页面上的所有元素并为其添加一个类。但是他们中的两个不应该得到这个课程。

$(document).on('click', '[data-show-link]', function() {
    var $this = $(this);
    $('[data-show-id]').toggle();
    $('*').not($this).not('[data-show-id]').toggleClass('get-opacity'); // ?
    event.preventDefault();
});

http://jsfiddle.net/ynts/8hLQG/

2 个答案:

答案 0 :(得分:0)

改变这个:

$('*')

到此:

$('.wrap').children()

Demo

答案 1 :(得分:0)

$("p").not("[data-show-id]").toggleClass('get-opacity');

JSFIDDLE : Isn't this you're looking for ?

相关问题