JavaScript DHTML/Node Operation/getAttribute

Материал из Web эксперт
Перейти к: навигация, поиск

Display attributes for hyper link

   <source lang="html4strict">

<html> <head>

   <title>Show Attribs</title>
   <script type = "text/javascript">
   function showattribs(e) {
       var e = document.getElementById("website");
       var elemList = "";
       for (var element in e) {
           var attrib = e.getAttribute(element);       
           elemList = elemList + element + ": " + attrib + "\n";
       }
       document.write(elemList);
   }
   </script>

</head> <body> <a onclick="showattribs()" href="http://www.google.ru" id="website">link</a> </body> </html>

 </source>
   
  


"getAttribute()" Example

   <source lang="html4strict">

   

<html> <body> <script language="JavaScript"> function function1(){

   var m = document.getElementById("myDiv").getAttribute("id");
   alert(m);

} </script>

This is a div element

<input type="button" value="Get id attribute value" onclick="function1();"> </body> </html>


 </source>