further explanation of the use of the e.target.
Hi. I generally know the use of the e.target, we use it to select the specific element clicked, but i still dont fully understand this term.. I know when we want to remove or add a list item element for example, we first get a ref to the specified html element that we clicked on with a simple if statement.
anyone can explain it better?
Steven Parker203,207 Points
It depends on what the handler is intended to do. For example, if clicking on a button changes the color of the page main title, then the handler will have no need for the event object (or the "target" attribute).
But if the handler does something relative to the item clicked, then the event target gives you a starting point to perform the DOM traversal with. Whether a condition ("if") would be involved is another matter. For example, if you wanted clicking on a paragraph to change its font to bold, you would not need "if", but you would use the event target to set the font weight.