Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
98
rated 0 times [  101] [ 3]  / answers: 1 / hits: 21243  / 14 Years ago, mon, october 11, 2010, 12:00:00

I need to get the actual html code of an element in a web page.


For example if the actual html code inside the element is "How to fix"


Running this JavaScript:


getElementById('myE').innerHTML

Gives me "How to fix" which is the parsed HTML.


How can I get the unparsed "How to fix" using JavaScript?


More From » html

 Answers
46

What you have should work:



Element test:



<div id=myE>How to&nbsp;fix</div>​


JavaScript test:



alert(document.getElementById(myE​​​​​​​​).innerHTML); //alerts How to&nbsp;fix


You can try it out here. Make sure that wherever you're using the result isn't show &nbsp; as a space, which is likely the case. If you want to show it somewhere that's designed for HTML, you'll need to escape it.


[#95362] Thursday, October 7, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wilson

Total Points: 27
Total Questions: 93
Total Answers: 93

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
wilson questions
Tue, Aug 9, 22, 00:00, 2 Years ago
Wed, May 11, 22, 00:00, 2 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Wed, May 13, 20, 00:00, 4 Years ago
;