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.

docs: http://api.jquery.com/data/


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -