Table Maker3schools TranslateImage CompressorFavicon Icon GeneratorCrop & Resize Image
Apu
Apu June 03, 2023 . #alt . #Attribute

How to add alt text to an image using JavaScript

How to add alt text to an image using JavaScript. If you are thinking about this,then in this article, you are going to learn that.

 <img src="https://app.3schools.in/logo.png">

In the above image element, there is no alt attribute . So, we will add an alt text to this element in javascript.

set image's alt attribute in javascript
  <img id="myImg" src="https://app.3schools.in/logo.png">

 <script>
  let img = document.querySelector('#myImg')
  img.alt="logo";
 </script>
Try it Yourself »
save
listen
AI Answer
Write Your Answer
loading
back
View All