I have something like this:
<div class="content">
<a href="#">A</a>
</div>
<div class="content">
<a href="#">B</a>
</div>
<div class="content">
<a href="#">C</a>
</div>
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.You should use the "siblings()" method, and prevent from running the ".content a" selector over and over again just for applying that effect:
HTML
CSS
Javascript
See here: http://jsfiddle.net/3bzLV/1/
You can also use the jQuery
.siblings()
method:HTML
Javascript
Working demo: http://jsfiddle.net/wTm5f/
You can use the
not
function rather than the:not
selector: