Deal with Duplicate ID - Javascript jQuery Selector

Javascript examples for jQuery Selector:id

Description

Deal with Duplicate ID

Demo Code

ResultView the demo in separate window

<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>

Related Tutorials