I'm trying to get the data-id
attribute after a click on the appropriate div. This is my html structure:
<div id="existing-risorse-list">
<div data-id="30">Cabina Cb</div>
<div data-id="32">Risorsa1 R1</div>
<div data-id="33">Cabina2 Cb2</div>
</div>
Essentially when the user click on Cabina Cb
I want return the id 30
, this is my code:
$(document).on('click', '#existing-risorse-list div', function()
{
var this_id = $(this).attr('data-id');
alert(this_id);
});
the event is fired correctly but the alert return
undefined
What am I doing wrong?