I am using this (jQuery) to replace everything
with
to eliminate validation errors: $("<...">

Replacing everyone with <br/">

I am using this (jQuery) to replace everything <br>

with <br />

to eliminate validation errors:

$("<br>").replaceAll("<br />");

      

but this does not reduce validation errors. Does authentication validate the original source?

+2


source to share


5 answers


There is no reason for this. XHTML is dead. Switch your doctype to html 5 and fall back to happy using closed tags:



<!DOCTYPE html>

      

+3


source


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 />

+11


source


Validators don't run javascript. They parse the HTML and compare it to the schema for the declared doctype.

You will need to replace <br>

in source files / views, not client side.

+5


source


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!

+1


source


first, as said, validators check the html file and don't run anything. Also, if you want the html to be valid, there is much more to it than of course ... why don't you just use an html editor?

0


source







All Articles