Reputation: 1630
I have a wrapper div and inside a button and a hidden div. When pushing the button the div shall be displayed. I don't want to use ids because the construction apears several times on the webpage. What is the right jquery command?
HTML
<div class="wrap">
<div class="button"> see more </div>
<div class="moreInfos"> Lorem ipsum... </div>
</div>
CSS
.moreInfos{ display: none;}
jQuery
$(".wrapp").on('click', '.button', function(){
$(this).parent('.moreInfos').css('display', 'block');
});
Upvotes: 1
Views: 89
Reputation: 15122
You were very close. Use parent().find()
$(this).parent().find('.moreInfos').css('display', 'block');
Also, you have a type $(".wrapp") extra 'p'.. just
$(".wrap")`
You also have a typo here: not diplay
, its display
Upvotes: 4
Reputation: 17927
If the click event is bound to the button:
$(this).parent().find(".moreInfos").show();
if the click event is bound to the wrapping div:
$(this).find(".moreInfos").show();
FIDDLE http://jsfiddle.net/BeNdErR/acN6R/8/
Upvotes: 6
Reputation: 33880
Try using siblings:
$(".wrap").on('click', '.button', function(){
$(this).siblings('.moreInfos').show();
});
Fiddle : http://jsfiddle.net/acN6R/5/
Upvotes: -1