javascript - how can i get attribute in div with jquery -
this code firebug, want data-name value
<div id="listdata"> name1 <img src="images1" data-name="data01"> name2 <img src="images2" data-name="data02"> name3 <img src="images2" data-name="data03">
how can attribute data-name click jquery
you can use data
.
$('#images1').data('name');
to data-name
of clicked image.
$(document).ready(function () { $('#listdata').on('click', 'img', function () { alert($(this).data('name')); }); });
demo: https://jsfiddle.net/tusharj/a0468f8k/
store arbitrary data associated matched elements or return value @ named data store first element in set of matched elements.
Comments
Post a Comment