HTML DOM alt Property
Complete Image Object Reference
Definition and Usage
The alt property sets or returns an alternate text to be displayed, if a
browser cannot show an image.
Syntax
imageObject.alt=alternate_text
|
Example
The following example changes the alternate text of an image:
<html>
<head>
<script type="text/javascript">
function changeAlt()
{
document.getElementById("compman").alt="Man using computer"
}
function alertAlt()
{
alert(document.getElementById("compman").alt)
}
</script>
</head>
<body>
<img id="compman" src="compman.gif" alt="Computerman" />
<br />
<input type="button" onclick="changeAlt()"
value="Change alt text">
<br /><br />
<input type="button" onclick="alertAlt()"
value="Alert alt text">
</body>
</html>
|
Try-It-Yourself Demos
Change the
alternate text of an image
Complete Image Object Reference
|
|
Get Your Diploma!
W3Schools' Online Certification Program is the perfect solution for busy
professionals who need to balance work, family, and career building.
The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate is for developers who want to document their knowledge of JavaScript and the HTML DOM.
The XML Certificate is for developers who want to document their knowledge of XML, XML DOM and XSLT.
The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.
The PHP Certificate is for developers who want to document their knowledge of PHP and SQL (MySQL).
|
|