Interview Question
Country: United States
Nothing good, its a bad practrice...
It's trying to prevent the default behavior of an anchor element and execute some script instead.
- From the semantics point of view:
An anchor tag should "link" (for example to a document or an specific location of the current document), if we are looking to perform a custom action the element should be a button, not an anchor.
- From the "Separation of concerns" point of view
Using inline scripts is discouraged, that practice leads to a non-maintainable code and in fact its just a hack. Attaching an event listener and preventing the default would be the way to go.
- Content Security Policy
On sites where configured, CSP will block inline scripts execution, therefore this wouldn't work...
Both the href and the on click are calling JavaScript funtions. The href cancels out the do something function.
- TheShocker1999 December 02, 2015