Hide all but $(this) via :not in jQuery selector

Kordonme picture Kordonme · Aug 25, 2009 · Viewed 87.4k times · Source

Advanced title, simple question:

How can I do the following in jQuery (hiding everything except $(this))?

$("table tr").click(function() {
    $("table tr:not(" + $(this) + ")").hide();
    // $(this) is only to illustrate my problem

    $("table tr").show();
});

Answer

Alex Gyoshev picture Alex Gyoshev · Aug 25, 2009
$(this).siblings().hide();

Traversing/Siblings