JavaScript Reference/Javascript Methods/getAttribute
"getAttribute()" Example
<source lang="javascript">
<html> <body> <script language="JavaScript"> function function1(){
var m = document.getElementById("myDiv").getAttribute("id"); alert(m);
} </script>
<input type="button" value="Get id attribute value" onclick="function1();"> </body> </html>
</source>
"getAttribute()" is applied to
<source lang="javascript">
+----------------+--------------------------------------------------------------+ | Applied_To |<a> <acronym> | | |<address> <applet> | | |<area> | | |<base> <basefont> | | | <bgsound> |
| ||| |<body>
| | |<button>| | | | | |
| |<col> | | |<colgroup> <comment> | | |currentStyle <custom> | | |
| | | <dir> ||
| |
- | | |<embed> <fieldset> | | | <form> | | |<frame> <frameset> | | |<head> <hn> | | |
<html> || | <iframe> | | |<img> <input type="button"> | | |<input type="checkbox"> <input type="file"> | | |<input type="hidden"> <input type="image"> | | |<input type="password"> <input type="radio"> | | |<input type="reset"> <input type="submit"> | | |<input type="text"> | | |<isindex> | | |<label> <legend> |
| |- <link> | | |<listing> <map> | | |<marquee> <menu> | | |<meta> <nobr> | | |<noframes> <noscript> | | |<object>
| | |<optgroup> <option> | | |
<param> | | |<plaintext>
| | |runtimeStyle | | || | |<script> <select> | | | | | || | |style <style> | | | | | |<tbody> | | |
<textarea> | | |<tfoot> | | |<thead> <title> |
| || | | | | |userProfile | | |
<xmp> | +----------------+--------------------------------------------------------------+ </source> "getAttribute()" Syntax, Parameters and Note
<source lang="javascript"> Note: Returns the attribute.
Syntax:
objectName.getAttribute(param1, param2) document.getElementById("elementID").getAttribute(param1, param2) document.all.elementID.getAttribute(param1, param2) // IE only Parameters: param1 Required; the attribute"s name.
</source>