On element click, get img src attribute value - Javascript jQuery

Javascript examples for jQuery:Image

Description

On element click, get img src attribute value

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <title>Get image src</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.js"></script> 
  <script type="text/javascript">
    window.onload=function(){//from www  .  j ava2s. c  o m
$("#img").on('click', function() {
    $("p").html($(this).attr('src'));
});
    }

      </script> 
 </head> 
 <body> 
  <img src="http://www.java2s.com/style/demo/Google-Chrome.png" id="img"> 
  <p id="para"> Hi </p>  
 </body>
</html>

Related Tutorials