Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get div and full inner content in javascript?

I want get div inner content in javascript

Ex:

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

This is my html code. i know only div id (content). but i want retrieved main div and their inner content via javascript like..

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

Also i want retrieved content div attribute also like style, class name etc.

like image 630
Sankar Pandi Avatar asked Jan 02 '26 08:01

Sankar Pandi


1 Answers

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

like image 59
Prasath K Avatar answered Jan 03 '26 21:01

Prasath K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!