Apu
June 03, 2023 .
#alt
.
#Attribute
❌
How to get element by alt attribute in JavaScript
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 »
save
listen
AI Answer
How to get element by alt attribute in JavaScript
0
In this article, you will learn how you can get the element by alt attribute using JavaSc…
asked
Apu
0 answers
2915
In this article, you will learn how you can get the element by alt attribute using JavaSc…
Answer Link
answered
Apu