-2

I am new to web designing, please help me with the difference between HTML and innerHTML with example. I have explored for the same but dint find the exact difference between both. Please help me with this.

BravoV
  • 11
  • 1

3 Answers3

2

innerHtml is the html inside a parent element, but not including the parent.

ex:

<div>
   <span></span>
</div>

The span is the innerHTML of the div whereas the entire block is HTML

TGH
  • 38,769
  • 12
  • 102
  • 135
1

jQuery html() execute script while If you set innerHTML property scripts are not executed.

bumbumpaw
  • 2,522
  • 1
  • 24
  • 54
0
<html>
<head>
<script type="text/javascript">
function getInnerHTML()
  {
  alert(document.getElementById("tr1").innerHTML);
  }
</script>
</head>
<body>

<table border="1">
<tr id="tr1">
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr id="tr2">
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="getInnerHTML()" value="Alert innerHTML of table row" />

the innerHTML is set or get the the HTML of the begin tag to the end of the tag

the example just return :

<th>Firstname</th>
<th>Lastname</th>
Pang
  • 9,564
  • 146
  • 81
  • 122
samuel
  • 1