Javascript examples for jQuery Selector:id
Deal with Duplicate ID
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.js"></script> <script type="text/javascript"> $(window).load(function(){//from w ww . j av a 2 s .c o m $("span").click(function () { var element = $(this), userid = element.data("userid"); console.log(userid); }); }); </script> </head> <body> <span class="click" data-userid="23">Click</span> <span class="classtwo" data-userid="23">Click class two</span> </body> </html>