I have the following HTML:
<div id="wrapper">
<div class="p1">
<a href="#" class="quickFlipCta"><img src="Test Pictures/QuestionMark.gif" /></a>
</div>
<div class="p2">
<a href="#" class="quickFlipCta"><img src="Test Pictures/flower.gif" /></a>
</div>
</div>
I have a function that is initiated when the user clicks on a link:
$('a').click(function(){
//some code here
});
Within the function, I want to access the “wrapper” div. What would be the best way of doing this? I have tried:
$('a').click(function(){
$(this).parent().parent().
//modification to wrapper
});
But that does not seem to be working.
That is perfectly valid, are you sure your click function is being called?
The best way would be to use an id. Just use
$("#wrapper")You can also use
.closestlike this$(this).closest('#wrapper')although i would recommend the id method over .closestCheck your click function is being called by calling an alert or console.log