I have a HTML document like below:
<td>
<div class="commentLink">
<a href="javascript:ShowBox()">Show</a>
</div>
<div class="hiddenBox">
<!-- Hidden content -->
</div>
</td>
The div element with class="hiddenBox" is hidden by default. On clicking the "Show" link, I want to show the hidden div. I tried this but it doesn’t work:
function ShowBox() {
$(function(){
$(this).parent().siblings(".hiddenBox").show();
});
}
The class hiddenBox occurs multiple times in my document, but I want only the sibling to show.
The problem is that
thisin your function won’t be the<a>element. You can change your inline handler like this to fix it:Ah just noticed, additionally you’ll need to reference the
thisoutside of the ready handler.I assume you’ve set it up this way in case someone clicks the link before the DOM is loaded.