JavaScript Reference/Javascript Properties/id

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

"id" Example

   <source lang="javascript">
   

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

  var id = elem.id;
  alert("This element"s id attribute is set to \"" + id + "\"."); 

} </script>

Click in the following image to display the id.

<img id="myImg" src="yourimage.jpg" onclick="getID(this);"> </body> </html>


     </source>
   
  


"id" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |<a> <acronym> | | |<address> <applet> | | |<area> | | |<base> <basefont> | | | <bgsound> |

| |
|

| |<body>
| | |<button> |

| |
|

| | <col> | | |<colgroup> <comment> | | |<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> <nobr> | | |<noframes> <noscript> | | |<object>
      | | |<optgroup> <option> | | |

      <param> | | |<plaintext>

                               |
      |                |                                                       |
      |                |                                                     |
      |                |                          <script>                      |
      |                |<select>                                               |
      |                |                                                |
      |                |                        <style>                       |
      |                |styleSheet                                               |
      |                |                                                  |
      |                |<tbody>                                                   |
      |                |                                                       |
      |                |
        | | | <xml> | | |<xmp> | +----------------+--------------------------------------------------------------+ </source>

        "id" Syntax and Note

        <source lang="javascript"> Note: Read and write property. Specifies the element identifier.

        Syntax:

        document.getElementById("elementID").id = value document.all.elementID.id = value // IE only


        </source>

      |

      | |<textarea> <tfoot> |

      | |
      <thead> | | |<title>