Replacing everyone with <br/">
JQuery will only run after the document has been processed. The page loading process will happen as follows:
- Request for a page
- The page is sent to the client machine
- Loading pages
- Page verified
- JQuery Fires
- tags are replaced
I would recommend to just search and replace on all tags <br>
and replace them with<br />
source to share
The HTML is parsed into the DOM (step 3 in Gary's column) where <br>
both <br />
are considered equal. Adding an element to an HTML page via JavaScript, whether you use jQuery or some other means, will parse your element and add it to the DOM. What the internal HTML looked like is no longer important as far as the browser is concerned.
You can see it yourself if you use innerHTML
. Place the following in any HTML document (doesn't matter if it's XHTML, HTML4, or HTML 3.2):
<p onclick="alert(this.innerHTML);">BR: <br />self close</p>
<p onclick="alert(this.innerHTML);">BR: <br>open</p>
<p onclick="alert(this.innerHTML);">BR: <BR>open capitals</p>
Download it in your browser and click on it.
In IE all three options are displayed as "<BR>"
, on FF, Chrome, Opera all three options are displayed as "<BR>"
. This is how browsers render HTML internally. Using valid HTML or invalid HTML with JavaScript will not change this. Worse: The internal HTML representation is not valid XHTML, even if the document is there!
source to share