get the span data content using jquery
how to get the different data values from dynamic span elements using jquery,check the below code
1 2 3 4 5 6 7 8 |
<span data-name="vasanthan" data-country="india" class="testspan" >first</span> <span data-name="Ericson" data-country="USA" class="testspan" >second</span> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script> $(".testspan").click(function(){ alert($(this).attr("data-country"));alert($(this).attr("data-name")); }); |