Quick Question.
Should we put Javascript in the HREF or use onClick (event)?
Are there any pros/cons to using either one. Personally I think it’s easier/cleaner to simply put code in the href, and not have to return false or worry about jumping to #
Are there any known browser specific issues with each method…
Examples:
<a href="javascript: alert('foo!');">Click Me</a>
<a href="#" onClick="alert('foo!');return false">Click Me</a>
<a href="javascript:void(0)" onclick="alert('foo!');">Click Me</a>
1) Rather use onclick. Be sure to have a rational fallback URL in
hrefwhen JS is not allowed.2) Rather than
onclick="...", you should use event handler.Find elements using jQuery or XPath, and then for each, call
element.addEventListener().Or the old way…