[HN Gopher] HTML event handler attributes: down the rabbit hole
       ___________________________________________________________________
        
       HTML event handler attributes: down the rabbit hole
        
       Author : eatonphil
       Score  : 7 points
       Date   : 2022-04-26 20:20 UTC (2 hours ago)
        
 (HTM) web link (datastation.multiprocess.io)
 (TXT) w3m dump (datastation.multiprocess.io)
        
       | lifthrasiir wrote:
       | > I'm not sure what `$name` is but `$body` is the string passed
       | to the handler attribute in HTML.
       | 
       | The name of the synthesized function is the attribute name
       | itself. So `<button onclick="alert(arguments.callee.name)">` will
       | alert "onclick" on click.
        
         | eatonphil wrote:
         | Good example. Thank you!
        
       | phillipseamore wrote:
       | I reach out for HTML events instead of addEventListener all the
       | time. I get free event addition when dynamically adding content,
       | also removal and tidying up after elements are removed - no
       | memory leaks from unused event listeners. Plus it's obvious from
       | browsing the code what different elements are hooked up to. I get
       | called out on this often, but no one can argue with the ease of
       | use and performance.
        
         | chris37879 wrote:
         | I prefer them too for the same reasons, they're even available
         | with a really similar syntax in React's JSX extension: <button
         | onClick={onClickHandler}>
         | 
         | I'm a big fan of the data attributes for the same reason, they
         | bind onto the actual element they belong with, they're
         | available in JS and CSS, and they add semantic meaning to your
         | markup when you're reading the source.
        
       ___________________________________________________________________
       (page generated 2022-04-26 23:02 UTC)