When a browser encounters invalid HTML, it has to take an educated guess as to what you meant to do—and different browsers can come up with different answers.
Valid HTML is the only contract you have with the browser manufacturers.
They describe validation as an ideal goal, but not something that is a black-and-white issue. The HTML4 specification is not perfect, and some things that were arguably correct — such as starting an ordered list at a point other than 1 — were invalid HTML.
When you first enter the JSLint validation page, there are a few checkboxes to check in the Options box I’d like to recommend to anyone getting confused: If your code in the specific file you’re validating, it’s easy to specify those dependencies to avoid having throw an error.
Just enter this code at the top of your Java Script file (naturally, replace the names below with theobjects/methods you use): Some people prefer to navigate to the JSLint page, paste in your code, and validate it, while other people feel they become faster if they can do it natively in their preferred development environment.
It uses the XHTML 1.0 Strict doctype as its rule set to validate against.
There are a few errors in the document, which you’ll discover below using the W3C HTML validator.
As the saying goes: Learn the rules so you know how to break them properly.
There are two very powerful reasons to validate your HTML as you author it: Validation is your early-warning system about introducing bugs into your markup that can manifest in interesting and hard-to-determine ways.
When I wrote about validating CSS, some of the feedback was that if you validate/promote valid HTML, naturally you should validate your CSS.
With that sentiment, I’d argue that it’s as, if not more, important to also validate your Java Script code (if you don’t agree, skip to the question at the end of this post, and give me a reply to that).
This is one of the biggest reasons for the rapid adoption and spread of the web.