This is a bad idea because ...
1) For a long time there was a reasonable emphasis on a clear separation between content, style and script. Muddying your JS HTML is not consistent with this.
2) More importantly, you have much less control over your events. In particular:
you can only associate one event of each type with DOM-zero events (these are what are built-in), so you cannot have two click event handlers
If an event is specified in a string, JS is indicated as a string (attribute values ββare always strings) and evaluated when the event fires. Assessment of evil.
You are faced with the need to reference named functions. This is not always ideal (event handlers usually accept anonymous functions) and have implications for the function, which should be global
In short, handle events centrally through the dedicated addEventListener API or through jQuery or something like that.
Utkanos
source share