Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one validate html that's generated from JS running in the browser?

The page in question has very skeletal html sent over the wire to facilitate the building of a complicated UI in javascript.

I'm now encountering a strange browser compatibility issue that feels very much like I've got a markup problem somewhere on the page.

I've validated the page as it comes across the wire using the W3C tool and ensured there are no issues in that html. I've also tried validating the output of running on the browser console:

document.getElementsByTagName('html')[0].outerHTML

I find that the output of the above introduces lots of new issues, such as removing the trailing '/' in self closing tags. This added noise is distracting, but it also makes me uneasy about validating this method.

How do you validate markup that's rendered client side?

like image 796
Henry Rose Avatar asked Jan 14 '11 00:01

Henry Rose


People also ask

How do you check if a HTML is valid?

The World Wide Web Consortium provide a simple online tool (https://validator.w3.org/) that automatically check your HTML code and point out any problems/errors your code might have, such as missing closing tags or missing quotes around attributes.

How do you check JavaScript code in HTML?

For most browsers, to view inline JavaScript in the HTML source code, do one of the following. Press the Ctrl + U keyboard shortcut. Right-click an empty area on the web page and select the View page source or similar option in the pop-up menu.

How do you validate a page in HTML?

The W3C HTML validator Note that you can also validate pages in the W3C validator from directly within the Opera browser by simply right/Ctrl-clicking and selecting the “Validate” option.


1 Answers

When elements are created on the client, they are created correctly by the browser - there really isn't anything to validate. The only time you'd need to validate any markup is if you're actually assigning outerHTML/innerHTML = some markup from the server. If that's the case, just log out the results on your server and run them through the standard HTML validators.

like image 106
Paul Alexander Avatar answered Oct 18 '22 20:10

Paul Alexander