Fix a function that assigns event handler functions to an array of nodes the wrong way
Fix the following function.
- When you click on a node, an alert box is supposed to display the ordinal of the node. But it always displays the number of nodes + 1 instead.
[codepen_embed height="265" theme_id="dark" slug_hash="WpdzvR" default_tab="js,result" user="kavitshah8"]See the Pen attaching eventHandler incorrect by Kavit Shah (@kavitshah8) on CodePen.[/codepen_embed]
Solution
Below codepen shows five different ways of solving the problem
[codepen_embed height="265" theme_id="0" slug_hash="zZpWvL" default_tab="result" user="kavitshah8"]See the Pen attaching eventHandler correct by Kavit Shah (@kavitshah8) on CodePen.[/codepen_embed]