Reputation: 2309
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 ??
Upvotes: 0
Views: 209
Reputation: 4392
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.
Upvotes: 1
Reputation: 7935
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.
Upvotes: 1
Reputation: 5462
It works if you type document.getElementById
instead of document.getElementBydId
=)
You just mistyped..
EDIT: Look here, it works! http://www.jsfiddle.net/rVa9t/
Upvotes: 0