JQuery: How to select all elements with same class besides the one clicked?
10,011
Solution 1
You could use not()
:
$('div.test').click(function(){
var notClicked = $('.test').not(this);
});
Solution 2
Try this:
$('.test').bind('click', function() {
var not_clicked_elements = $(this).siblings('.test');
};
Author by
Antonio Moore
Updated on July 18, 2022Comments
-
Antonio Moore almost 2 years
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?
-
Antonio Moore about 12 yearsjsfiddle.net/KGS25 I have this but I can't figure out what I;m doing wrong?
-
Nicola Peluchetti about 12 years@user1274383 what is the desired behaviour?