1

I have a simple Javascript that gets an element by ID and inserts a text with a break line tag using the innerHTML method. The page is in XHTML 1.0 so I am using <br />.

var dom = document.getElementById(elmt);
var message = "This is a test";

dom.innerHTML = message + "<br />";

I have tested in Chrome and in IE and they both change the tag to <br>. I am performing some .search with <br />, but it fails because it is not including the forward slash. Is there a reason for this? How can I force it to send <br />?

Rick
  • 2,288
  • 18
  • 66
  • 98
  • I have tried `"
    "` and `"
    "` and they both print `
    `
    – Rick Oct 11 '14 at 02:22
  • works fine -- http://jsfiddle.net/qLb1e3zw/ -- you don't see the (/) in the html just the (
    )
    – Tasos Oct 11 '14 at 02:22
  • I am comparing the innerHTML. If you check with Firebug or whatever element inspector in the browser, you'll see that it converted to
    . See [here](http://i.imgur.com/4zR7FuZ.png).
    – Rick Oct 11 '14 at 02:27
  • 1
    That's because In HTML, the
    tag has no end tag. In XHTML, the
    tag must be properly closed, like this:
    . so in html (/) gets stripped off
    – Tasos Oct 11 '14 at 02:28
  • Is there another way to go about this so that it validates to XHTML 1.0 strict then? – Rick Oct 11 '14 at 02:32
  • Not in HTML5 -- http://www.dummies.com/how-to/content/the-relationship-between-html5-and-xhtml.html – Tasos Oct 11 '14 at 02:35

0 Answers0