Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

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>

Open in new window

Avatar of wdosanjos
wdosanjos
Flag of United States of America image

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
Avatar of David S.
David S.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hankknight

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.
Using AJAX for this seems like using a cannon to shoot a fly.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial