jQuery HTML Element How to - Get url of an image link








Question

We would like to know how to get url of an image link.

Answer


<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head><!--  w ww .  j a  v a 2 s  . co  m-->
<body>
  <div class="lp-element lp-pom-image" id="lp-pom-image-167">
    <a href="" target=""><img src="http://placehold.it/100x80" alt="" /></a>
  </div>
  <script>
jQuery(".lp-pom-image").click(function() {
  console.log($("img", this).attr("src"));
  return false;
}); 
</script>
</body>
</html>

The code above is rendered as follows: