hankknight
asked on
JavaScript: innerHTML removes closing slash!
When I use innerHTML, <br /> becomes <br>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
</head>
<div id="v">
<p>The / in these <br/> tags does not show when innerHTML is used. <br /> The slash vanishes!</p>
</div>
<script type="text/javascript">
alert(document.getElementById('v').innerHTML);
</script>
</body>
</html>
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>.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there a good way to get THE ACTUAL CONTENT?
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.
ASKER
Using AJAX for this seems like using a cannon to shoot a fly.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.