How to select an item that is not 'this'?

I have a list of divs all with the same class, I want to apply a function to all of them that are not click ( this), how can I select !thisusing jQuery?

UPDATE: I did this and it does not work, no idea why?

    $("li").each(function(){
        $("li").not(this).click(function(e) {
            $(this).hide();
        });
    });

UPDATE 2: this is all the actual code:

$(".mark").click(function(e) {
    e.preventDefault();
    var id = "#" + $(this).parent().parent().parent().parent().attr("id") + " ";

    var currentStatus = "deleted"; // to be replaced with actual status
    var currentStatusClass = "." + currentStatus + "-heading";
    $(id + currentStatusClass).show();

    $(id + ".edit-headings").click(function(){
        $(this).find(".headings-status").show().addClass("bg-hover");

        $(id + ".headings-status").click(function() {
            $(id + ".headings-status").not(this).hide();
        });
    });
});
+5
source share
5 answers

Use function .not():

$('.yourclass').click(function() {
    $('.yourclass').not(this).yourFunc();
});
+3
source

Take a look at the jQuerys function not: http://api.jquery.com/not/

$('div').not(this).doSomething();

As for your update, try:

        $("li").click(function(e) {
            $("li").not(this).hide();
        });
+7
source

$('div').not(this), , .

+1

:not() .not()

$this;

function myFunction(){
      // stuff here // and use $this for element reference
}


$('yourElement:not(.selected)').on('click',function(){
    // (make sure to add '.selected' to the new one and toggle existant)
    $('.selected').removeClass('selected');
    $this = $(this);
    $this.addClass('selected');

    myFunction();
});
0

:

var newStatus = $(this).className().replace("contribution-", "");

className .

:

var cls = $(this).attr('class').replace('contribution-','');
$(this).removeClass().addClass(cls);
0
source

All Articles