megacolorboy

Back

Published on May 28th, 2020

jQuery

Select all elements except the current element

If you don't want the current element to be selected in an array of elements that belongs to same class or type, just use the method like the example below:The above code will change the text for all buttons except the current element.

1 minute read

If you don't want the current element to be selected in an array of elements that belongs to same class or type, just use the .not() method like the example below:


$(".btn").click(function(){
    $(".btn").not(this).text('selected');
});

The above code will change the text for all buttons except the current element.