Thursday, January 10, 2008

HTML and Case Sensitivity

HTML and Case Sensitivity
Under HTML 4 and earlier, element and attribute names are case-insensitive. For example, the following two tags are equivalent:
<Increment x>
<Increment x>
This is not a problem in itself. The problem comes when novice programmers see HTML event handlers referenced in two different ways (like ONCLICK and onClick in the previous example) and assume event handlers can be accessed similarly in JavaScript. This is not the case. The corresponding event handler in JavaScript is onclick, and it must always be referred to as such. The reason that ONCLICK and onClick work in HTML is that the browser automatically binds them to the correct onclick event handler in JavaScript.

No comments: