Get attribute value from onClick event handler - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

Get attribute value from onClick event handler

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Page Title</title> 
   </head> 
   <body> 
      <img id="like1" src="http://www.java2s.com/style/download.png" style="width:23px;height:23px;" title="???" value="1" onclick="onClick(this)">
      asdf//  w w  w .  ja va 2 s.  c o m
      <img id="hate1" src="http://www.java2s.com/style/download.png" style="width:23px;height:23px;" onclick="onClick(this)" value="-1" title="asdf">
      asdf
      <script>
function onClick(int) {
  console.log(int.getAttribute('value'));
  console.log(int.getAttribute('value'));
}

      </script>  
   </body>
</html>

Related Tutorials