In this article, you will learn how you can get the element by alt attribute using JavaScript. Sometimes, we can't add any class or id attributes to an element. So,in that case, we can easily access that element by using its alt attribute.
Example : get img element by alt attribute. #
<img alt="text" src="https://app.3schools.in/logo.png">
<script>
let img = document.querySelector('img[alt="text"]')
console.log(img.alt);
</script>
Try it Yourself »
Comments (0)