I have heard many times that using JavaScript events, such as onClick()
, in HTML is a bad practice, because it\'s not good for semantics. I would like to know w
There are a few reasons:
I find it aids maintenence to separate markup, i.e. the HTML and client-side scripts. For example, jQuery makes it easy to add event handlers programatically.
The example you give would be broken in any user agent that doesn't support javascript, or has javascript turned off. The concept of progressive enhancement would encourage a simple hyperlink to /map/
for user agents without javascript, then adding a click handler prgramatically for user agents that support javascript.
For example:
Markup:
link
Javascript:
$(document).ready(function(){
$("#example").click(function(){
popup('/map/', 300, 300, 'map');
return false;
});
})