I have the following HTML
<div class="myclass" value="1">
<div>
<div class="myclass" value="">
<a class="popup" id="12" target="_blank" href="xxx">popup</a>
</div>
</div>
</div>
I am using jQuery with a click event on the popup class, and I am trying to get the value of the grandfather div with class “myclass” which is has a value “1” in the example. I’ve tried this but it returns me ‘undefined’
$('.popup').click(function(){
alert($(this).parent('.myclass').parent('.myclass').attr('value')
});
Its an unbalanced braces issue.
You need to close the alert
);or useclosestinstead ofparent: