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?
In jQuery, we can select elements with multiple classes using the . class selector.
The . class selector selects all elements with the specific class. The class refers to the class attribute of an HTML element. The class attribute is used to set a particular style for several HTML elements.
The * selector selects all elements. The * selector can also select all elements inside another element (See "More Examples").
Differentiate the concepts of ID selector and class selector: The only difference between them is that “id” is unique in a page and it is applied to one HTML element while “class” selector can apply to multiple HTML elements.
You could use not()
:
$('div.test').click(function(){
var notClicked = $('.test').not(this);
});
Try this:
$('.test').bind('click', function() {
var not_clicked_elements = $(this).siblings('.test');
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With