The rephrased title is: Extract the original file of the image
P粉087951442
P粉087951442 2023-09-13 19:36:22
0
1
512

I'm trying to get the src of a specific image on a web page. When I enter my code, the output is an undefined error.

Uncaught TypeError: Cannot read attribute of undefined (read 'getAttribute')

This is the HTML code

<div class="team-member-image border-radius-5px overflow-hidden">
      <img class="abc" alt="" src="images/team01.jpg">
</div>

This is js

`<script>
      var pic = document.getElementsByClassName("abc")[0].getElementsByTagName("img")[0];
      var src = pic.getAttribute('src');
      console.log(src);
</script>`

What could this problem be and how can I solve it.

P粉087951442
P粉087951442

reply all(1)
P粉665679053

Just call it once to get the element:

var pic = document.getElementsByClassName("abc")[0];
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template