tags:

views:

60

answers:

4

How do I get the values in between a DIV tag?

Example

<div id="myOutput" class="wmd-output">
    <pre><code><p>hello world!</p></code></pre>
</div>

my output values I should get is

<pre><code><p>hello world!</p></pre>
+5  A: 

First, find the element. The fastest way is by ID. Next, use innerHTML to get the HTML content of the element.

document.getElementbyId('myOutput').innerHTML;
meagar
JavaScript is case-sensitive, it should be `innerHTML`, otherwise will simply return `undefined`.
CMS
+4  A: 
document.getElementById("myOutput").innerHTML
programble
+1  A: 

innerHtml is good for this case as guys suggested before me,

If you have more complex html structure and want to traverse/manipulate it I suggest to use js libraries like jQuery. To get want you want it would be:

$('#myOutput').html()

Looks nicer I think (but I wouldn't load whole js library just for such simple example of course)

Lukasz Dziedzia
+1  A: 

Just putting all above with some additional details,

If you are not sure about that div having some id is not there on html page then to make it sure please use.

var objDiv = document.getElementbyId('myOutput');
if(objDiv){
  objDiv.innerHTML;
}

This will avoid any JavaScript error on the page.

Umesh Aawte