jquery toggling more than one div
i'm trying to make toggling div with only 1 javascript.
I tried this, the first div does what it was meant to do but the second doesn't.
Have a look.
<body>
<div>
<div>He
<div>You
<div id="Me"><a id="me">Me</a></div>
</div>
</div>
<div id="This">We
</div>
</div>
<div>
<div>1
<div>2
<div id="Me"><a id="me">3</a></div>
</div>
<开发者_如何学Python;/div>
<div id="This">4
</div>
</div>
<script>
$("#me").click(function () {
$(this).parent().parent().parent().siblings("#This").slideToggle("slow");
});
</script>
</body>
when i click me, we disappear, alright. But when i click 3, 4 doesn't disappear.
Ids are expected to be unique. For 'markers' you can use 'class' attribute. (not sure if this is the cause, but there is a good chance that it is)
if you don't want to add classes for whatever reason you can target multiple ids at once with jQuery. You still will need unique identifiers on your elements however.
If you want to toggle multiple ids in one call you should be able to do something like:
$('#id1, #id2, #id3').slideToggle();
精彩评论