Take the following html:
<div class="box">
<a href="javascript:;" onclick="toggle_content(1)">Toggle</a>
<h2>Some Title</h2>
<div class="box_content box_content_1"></div>
<div class="box_content box_content_2"></div>
</div>
<div class="box">
<a href="javascript:;" onclick="toggle_content(1)">Toggle</a>
<h2>Some Title</h2>
<div class="box_content box_content_1"></div>
<div class="box_content box_content_2"></div>
</div>
<script>
function toggle_content(key){
$('.box_content_'+key,$(this).parent()).toggle();
}
</script>
Basically, when the toggle link is clicked, I would like the toggle the element inside the same parent that has the matching class name. The code above doesn’t seem to do anything.
You can set the context of
thisintoggle_contentby usingcallhttp://jsfiddle.net/eyWBq/