Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select element which is not 'this'?

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

UPDATE: I've made this and it is not working, any ideas why?

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

UPDATE 2: this is the whole 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();
        });
    });
});
like image 767
ilyo Avatar asked Apr 30 '12 12:04

ilyo


2 Answers

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

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

Regarding your update, try:

        $("li").click(function(e) {
            $("li").not(this).hide();
        });
like image 154
Dennis Avatar answered Sep 26 '22 14:09

Dennis


Use the .not() function:

$('.yourclass').click(function() {
    $('.yourclass').not(this).yourFunc();
});
like image 20
Anthony Grist Avatar answered Sep 25 '22 14:09

Anthony Grist