Related articles: innerHTML
HTML DOM insertRow() method
Definition and Usage
Definition and usage
The insertRow() method is used to insert a new row in a specified position in a table.
InsertRow() method can be inserted into a new row at a specified location in the table
Syntax syntax
tableObject.insertRow(index)// index, add new lines
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Example
<html>
<head>
<script type=text/javascript>
function insRow()
{
document.getElementById('myTable').insertRow(0)//Look for controls in the document
}
</script>
</head>
<body>
<table id=myTable border=1>
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
</table>
<form>//Put controls in the form
<input type=button onclick=insRow()
value=Insert new row before the first row>//value is what is to be displayed on the control
</form>
</body>
</html>
In the js method, you can directly assign the tag content with id.innerHtml of paired tags without declaring variables in the js method
innerHTML is an attribute of the html tag. Most tags that appear in pairs have this attribute // tag attribute
is the character between the start label and the end label, excluding the label itself
for example
<p id=pp>aaaaaaaaa<span id=ss>bbbbbbbb</span> </p>
Here the p tag and span tag are nested together
Then the content of pp.innerHTML is
aaaaaaaaaa<span id=ss>bbbbbbbb</span>
The content of ss.innerHTML is
bbbbbbbbbbbbbb
===================================
A similar property is outerHTML
Then the content of pp.outerHTML is
<p id=pp>aaaaaaaaa<span id=ss>bbbbbbbb</span> </p>
The content of ss.outerHTML is
<span id=ss>bbbbbbbb</span>