I have following html structure for example.
<div class="message" data-id="4">
<div>
<div class="msg-button">
<span class="sms"></span>
</div>
<div>
<div>
<div>
<span class="sms"></span>
</div>
</div>
</div>
</div>
</div>
When i click on elements with class sms i need to get data-id attribute of element with class message.
What i've done using jquery. It doesn't work for me. How can i get parent element by class? Thanks in advance!
$('.sms').click(function(){
var id = $(this).parent('.msg-button').siblings('.message').data("id");
alert(id);
})
$(this).closest('.message').data("id");