I have a page dynamically created with buttons. I would like to find the corresponding button data-ids value if I click li link edit or show? I tried with closest () but without success.
<div class=\"btn-group\">
<button type=\"button\" class=\"btn dropdown-toggle actions\" data-ids=\"1\" data-toggle=\"dropdown\" aria-expanded=\"false\">
<span class=\"glyphicon glyphicon-edit\"></span>
</button>
<ul class=\"dropdown-menu\" role=\"menu\">
<li><a href=\"\" class="edit">Edit</a></li>
<li><a href=\"\" class="show">Show</a></li>
</ul>
</div>
<div class=\"btn-group\">
<button type=\"button\" class=\"btn dropdown-toggle actions\" data-ids=\"2\" data-toggle=\"dropdown\" aria-expanded=\"false\">
<span class=\"glyphicon glyphicon-edit\"></span>
</button>
<ul class=\"dropdown-menu\" role=\"menu\">
<li><a href=\"\" class="edit">Edit</a></li>
<li><a href=\"\" class="show">Show</a></li>
</ul>
</div>
...
JS
$('.edit').on('click', function(e) {
e.preventDefault();
var ids = $(this).closest('button.actions').attr('data-ids');
});
How could I do, seen that it is not a parent element? Thank you