JavaScript: innerHTML removes closing slash!

When I use innerHTML, <br /> becomes <br>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""> 
<html lang="en" xmlns=""> 

<div id="v">
 <p>The / in these <br/> tags does not show when innerHTML is used. <br /> The slash vanishes!</p>

<script type="text/javascript">

Open in new window

LVL 16
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

leakim971Connect With a Mentor PluritechnicianCommented:
Check this article :
Have a look at the end of this page :

So in your code you can left this tags away from your "analyse" and don't worry about the number of their occurences.
I think that happens because 'innerHTML' provides the HTML content of the control not the XHTML content.  In HTML, the BR tag is only <BR>.
David S.Connect With a Mentor Commented:
That's because the browser is using an HTML parser, not an XML parser for the page. If you view the innerHTML in IE versions before 9, the tags will even be in uppercase.
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

hankknightAuthor Commented:
Is there a good way to get THE ACTUAL CONTENT?
David S.Commented:
If it's a valid XHTML document, you could try using AJAX to request the page and use responseXML to find the elements you were interested in.
hankknightAuthor Commented:
Using AJAX for this seems like using a cannon to shoot a fly.
wdosanjosConnect With a Mentor Commented:
I don't think there is a way to get the original XHTML, because when you assign a value to innerHTML the browser uses it to decorate the DOM (which is not XHTML). So when you pull the information back it comes from the DOM, thus it's only HTML.
All Courses

From novice to tech pro — start learning today.