I’ve got the following HTML and because I’m using WordPress, I cannot change the class for each div.
<div class="show_hide">content1</div>
<div class="extended">extension of content 1</div>
<div class="show_hide">content2</div>
<div class="extended">extension of content 2</div>
My jQuery script is as follows:
<script type="text/javascript">
$(document).ready(function(){
$(".sliding").hide(0);
$(".show_hide").show(0);
$('.show_hide').click(function(){
$(".sliding").slideToggle(0);
});
});
</script>
Now, when clicking on the show_hide div, both div’s with class “extended” show. I would like to show only the extension the div clicked on. Can anyone help me with this?
If the
.extendedelement is the immediately following sibling of the.show_hideelement, you can usenext:If there are other elements in between, you can use
nextAll, and then reduce the selection to the first match (witheq):