Skip to content Skip to sidebar Skip to footer

How To Get Div And Full Inner Content In Javascript?

I want get div inner content in javascript Ex:
content
content
content

Solution 1:

Use getElementById() to get the element and innerHTML to get tht content

document.getElementById('content').innerHTML;

LIVE DEMO FOR INNERHTML

To get the content of the whole tag , use outerHTML

document.getElementById('content').outerHTML;

LIVE DEMO FOR OUTERHTML


Solution 2:

You can try this piece of code to retrieve inner content

var MyDiv1 = document.getElementById('content').innerHTML;  

Solution 3:

If you want to retrieve the content that is inside the div, you can use document.getElementById("content").innerHTML. This will return

content<br>content<br>content<br>


But if you want to retrieve the html with div tags included, you can try using document.getElementById("contents").outerHTML. This will return you

<div id="content" style="height: 20px; overflow: hidden">
 content<br>content<br>content<br>
</div>

Post a Comment for "How To Get Div And Full Inner Content In Javascript?"