Can't seem to be able to target nearest div with jQuery
I have the following HTML
<div class="outerBox">
<div class="innerBox">
//text
</div>
<div class="clickMe">
开发者_StackOverflow社区 <span class="icon"></span>
</div>
</div>
<div class="hiddenDiv">//hidden div</div>
I need to be able to show(".hiddenDiv") when I click ".clickMe" but for some reason I cen't seem to be able to target it... Tried all sorts of variations but nothing seem to work. Here's the latest:
$(".clickMe").click(function() {
$(this).parents().closest(".hiddenDiv").show();
});
How about this:
$(".clickMe").click(function() {
$(this).parent().next(".hiddenDiv").show();
});
Or this:
$(".clickMe").click(function() {
$(this).parent().siblings(".hiddenDiv").show();
});
Try this:
$(this).parent().siblings('.hiddenDiv').show();
try this:
$(".clickMe").click(function() {
$('.hiddenDiv', $(this).parents()).show();
});
fiddle: http://jsfiddle.net/maniator/Wpqz4/
Try this:
$(".clickMe").click(function(){
$(this).closest(".outerBox").next(".hiddenDiv").show();
});
精彩评论