Logan Serman Logan Serman - 1 month ago 8
jQuery Question

jQuery: exclude $(this) from selector

I have something like this:

<div class="content">
<a href="#">A</a>
<div class="content">
<a href="#">B</a>
<div class="content">
<a href="#">C</a>

When one of these links is clicked, I want to perform the .hide() function on the links that are not clicked. I understand jQuery has the :not selector, but I can't figure out how to use it in this case because it is necessary that I select the links using
$(".content a")

I want to do something like

$(".content a").click(function()
$(".content a:not(this)").hide("slow");

but I can't figure out how to use the :not selector properly in this case.


Try using the not() method instead of the :not() selector.

$(".content a").click(function() {
    $(".content a").not(this).hide("slow");