document.getElementById ("link"). href;
document.getElementById ("link"). Target;
document.getElementById ("img"). SRC;
document.getElementById ("img"). Width;
document.getElementById ("img"). Height;
document.getElementById ("Input"). Value;
So how do you get the value between <div></div> and <a></a>? such as <div id= "div" >aaa</div> in the Aaa,<a href= "#" id= "link" >bbb</a> in the BBB, also very simple, the use of innerHTML can be:
document.getElementById ("div"). InnerHTML;
document.getElementById ("link"). InnerHTML;
getElementById method
Returns a reference to the first object with the specified ID attribute value.
Grammar
Oelement = document.getElementById (sidvalue)
Parameters
Sidvalue required option. A string that indicates the value of the ID attribute
return value
Returns the first object with the same ID attribute value as the specified value.
Comments
If the ID belongs to a collection, the getElementById method returns the first object in the collection.
The getElementById method is equivalent to using the Item method on the all collection. For example, the following code sample shows how to retrieve the first element of ID as Odiv from the Document object.
Using the DHTML object model:
var ovdiv = Document.body.all.item ("Odiv");
Using the Document Object Model (DOM):
var ovdiv = document.getElementById ("Odiv");
Example
The following example shows how to use the getElementById method to return the first occurrence of the ID attribute value Odiv.
<script>
function Fngetid () {
Returns the collection of the "the"
var Ovdiv=document.getelementbyid ("ODiv1");
}
</script>
<div id= "ODiv1" >div #1 </DIV>
<div id= "ODiv2" >div #2 </DIV>
<div id= "ODiv3" >div #3 </DIV>
<input type= "button" value= "Get Names" onclick= "Fngetid ()" >
getElementById method
Returns the first name with the specified ID attribute value, for example, the ID of a text box in a Web page is called Text1
getElementById (Text1) can get the object of this Text1 box and use all the properties and methods of the text box
This is a JS method, meaning that the control ID to get the value of the element, such as a form in the package letter, label, and so on, they are form elements, there is an allocation of Id,getelementbyid () is to get the text value of these elements.
This is a JS method, meaning that the control ID to get the value of the element, such as a form in the package letter, label, and so on, they are form elements, there is an allocation of Id,getelementbyid () is to get the text value of these elements.
Program examples
<ptml> <pead> <script type= "Text/javascript" > Function Alignrow () {var X=document.getelementbyid (' MyTable '). Rows x[0].align= "right"} </script> </pead> <body> <table width= "60%" id= "MyTable" bo rder= "1" > <tr> <td> Line 1 cell 1</td> <td> Line 1 cell 2</td> </tr> <tr> <td> Line 2 cell 1</td> <td> Line 2 cell 2</td> </tr> <tr> <td> Line 3 cell 1</td> <td> 3 cell 2& lt;/td> </tr> </table> <form> <input type= "button" onclick= "Alignrow ()" value= "right to Zidi one line of text" > </form> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
The detachment is aligned with a cell partition
<ptml> <pead> <script type= "Text/javascript" > Function Aligncell () {var X=document.getelementbyid ( ' MyTable '). Rows[0].cells x[0].align= "Center"} </script> </pead> <body> <table id= "myTable" Bor Der= "1" width= "100%" > <tr> <td> cell 1</td> <td> cell 2</td> </tr> <tr> <t d> cell 3</td> <td> cell 4</td> </tr> </table> <form> <input type= "button" Onclic K= "Aligncell ()" value= "centered Zidi contents of a cell" > </form> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Change the value of colspan
<textarea id="runcode59430"><ptml> <pead> <script type= "Text/javascript" > Function Setcolspan () {var x=document.getelemen Tbyid (' myTable '). Rows[0].cells x[0].colspan= "2" x[1].colspan= "6"} </script> </pead> <body> <t Able id= "MyTable" border= "1" > <tr> <td colspan= "4" > Cell 1</td> <td colspan= "4" > Cell 2</td& Gt </tr> <tr> <td> cell 3</td> <td> cell 4</td> <td> cell 5</td> <td> Cell 6 </td> <td> cell 7</td> <td> cell 8</td> <td> cell 9</td> <td> cell 10</td > </tr> </table> <form> <input type= "button" onclick= "Setcolspan ()" value= "Change colspan value" > &L t;/form> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]