I'm using this (jQuery) to replace all <br>
s with <br />
to clear out validation errors:
$("<br>").replaceAll("<br />");
but it doesn't reduce any validation errors. Does validator check the original source?
I'm using this (jQuery) to replace all <br>
s with <br />
to clear out validation errors:
$("<br>").replaceAll("<br />");
but it doesn't reduce any validation errors. Does validator check the original source?
Validators do not run javascript. They parse the HTML and compare it to the schema for the declared doctype.
You will need to replace the <br>
in your source files / views and not on the client side.
JQuery will only fire after the document has been rendered. The process of the page loading will happen like the following
I would recommend just doing a site-wide find and replace on all <br>
tags and replace them with <br />
first, as has been said the validators check the html file, and does not run anything.
beside, if you want to the html to be valid, there much more than
of course.. why don't you just use an html editor?
JQuery runs on the client. You must change your source code with basic replace command on notepad++ for instance.
There is no reason to do this. XHTML is dead. Switch your doctype to html 5 and go back to happily using unclosed tags:
<!DOCTYPE html>
The HTML is parsed into the DOM model (step 3 in Gary's post), where <br>
and <br />
are considered equal. Adding an element to an HTML page through JavaScript, whether you use jQuery or any other means, will parse your element and add it to the DOM. How the internal HTML looked like is not important anymore for what the browser's concerned.
You can see this for 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>
Load it in a browser and click on it.
On IE all three variants show up as "<BR>"
, on FF, Chrome, Opera all three variants show up as "<br>"
. This is how the browsers represent the HTML internally. Using valid HTML or invalid HTML with JavaScript will not change this. Worse: the internal HTML representation is not valid XHTML, even when the document is!