开发者

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();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜