Image object property alt (alternate) in Javascript
The image object property alt use to set and retrieve the value of the alt attribute of an image. It specifies an alternate text for an image, in case an image can not be displayed, due to any reason. It returns a string that represents the alternate text for the image.
Syntax
 1 <image>.alt // to retrieve
 2 <image>.alt = <string> // to set
image : A image element object to set and retrieve the alternate text for an image
string : It specifies the alternate text for the image, if image not display
Image property alt (alternate)
 1 <html>
 2 <style>
 3   .container {
 4     margin: 10px 0;
 5   }  
 6 </style>
 7 <body>
 8 	<h1>The Image Object</h1>
 9 	<h2>Example</h2>
 10 	
 11 	<div>
 12 	  <img id="image" src="invalid.png" alt="Image not availble"
 13 	    width="300" height="200" />
 14 	</div>	
 15 	<p>
 16 	  <button onclick="access()">Access</button>
 17 	</p>
 18 	<p id="result"></p>
 19 	
 20 	<script>
 21 	function access() {
 22 	  const image = document.getElementById("image");
 23 	  const str = `The alternate text is : <b>${image.alt}</b>`;
 24 	  document.getElementById("result").innerHTML = str;
 25 	}
 26 	</script>
 27 </body>
 28 </html>
Image property alt (alternate)
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us