views:

27

answers:

4

I have an HTML document with the following code

    <html>
<head></head>
<body>
<div id="wrapper">
<div class="label">First Name : </div>
<div class="value">John Doe</div>
</div>
</body>
</html>

Using javascript I want to access the contents of div#wrapper as a string like

var s = '<div class="label">First Name : </div><div class="value">John Doe</div>';

tried

var wrapperContent = document.getElementBydId("wrapper").innerHTML; // returns First Name : John Doe

but this gives me only the text values. Anyways I can achieve this ??

A: 

use jquery's method

$('#wrapper').html 
gov
A: 

It works if you type document.getElementById instead of document.getElementBydId =)

You just mistyped..

EDIT: Look here, it works! http://www.jsfiddle.net/rVa9t/

joni
+1  A: 

What you posted should work.

I believe your problem is that you are trying to get the innerHTML of an element that does not have a parent yet.

Nican
false. His problem is that he mistyped ` getElementById `
joni
+1  A: 

innerHTML should work fine. For example, try document.getElementBydId("wrapper").innerHTML on this page.

Be sure you're executing the Javascript at either the end of the document, or within some incarnation of the window.onload event.

mway