At my website I have clickable hidden meta tags like page views or Google requests under every article.
This is the code I use:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function(){
$(".slidingDiv").slideToggle();
});
});
</script>
And this code for PHP:
<p class="postmetadata"><a href="javascript:;" class="show_hide">[Show/hide meta data]</a></p>
<div class="slidingDiv">
<p class="postmetadata">Aufrufe: <?php if(function_exists('the_views')) { the_views(); } ?> </p>
<p class="postmetadata"><?php if(function_exists('stt_terms_list')) echo stt_terms_list() ;?></p>
<p class="postmetadata"><?php if (function_exists('backlinks')) backlinks(); ?></p>
<br>
</div>
I use WordPress. The problem is, if I click on “Show/hide meta data” every article shows the meta data. I only want the meta data of the article I clicked. This is my website.
You have to click on the german “[Zeige/Verstecke Meta-Daten]”, which is equal to “[Show/hide meta data]”.
Using jQuery method .next(), this will work right now:
Using jQuery method .siblings(), this will work even if you rearrange the order of the elements:
Using jQuery method .closest(), this works even if you rearrange the elements depths:
Also, for jQuery/Prototype conflicts, see this: Prototype and jQuery together?
The simplest solution is to create a temporary context: