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 »