10

I guess I'm looking for an opposite to $(this).

If I have 3 elements with the same class how can I select only the elements I haven't clicked. EG:

<div class="test"></div>
<div class="test"></div>
<div class="test"></div>

And I click the middle div, how do I only implement effects on the first and last element?

4

4 に答える 4

17

使用できますnot()

$('div.test').click(function(){
    var notClicked =  $('.test').not(this);
});
于 2012-04-18T10:35:53.700 に答える
2

これを試して:

$('.test').bind('click', function() {
  var not_clicked_elements = $(this).siblings('.test');
};
于 2012-04-18T10:36:01.000 に答える
0

おそらく「not」セレクターを使用できます。

于 2012-04-18T10:36:04.587 に答える
-1

これを使用できます:

$(document).on("click",".test ",this,function(e){ 

   alert($(this).text());

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">nicole</div>
<div class="test">charlize</div>
<div class="test">megan</div>

于 2016-12-25T10:21:44.873 に答える