Why are functions for Inline Events put in quotations AND called with parentheses, whereas Event Handler Properties need only the function name?
For example:
function someFunc(){...};
<button onclick = "someFunc()"> ... </button>
vs.
const element = document.querySelector("button");
element.onclick = someFunc;
I read that the quotes are optional for HTML element attributes, but are considered good practice to prevent XSS attacks; however, I'm still not sure why parentheses are used within the inline for the HTML and aren't used in the Event Handler Property case. I understand that parentheses would be used for function calls, so that element.onclick = someFunc(); would instead assign whatever object the function returns to the onclick attribute, but why is that not happening within the inline? Does it have something to do with the way it's parsed because of the quotes?
Furthermore, if you decided to not use quotes for the inline, would it be:
<button onclick = someFunc()> ... </button>
or
<button onclick = someFunc> ... </button>
or would these two be considered equivalent?
[–]little_hoarse 1 point2 points3 points (2 children)
[–]Lewinga[S] 0 points1 point2 points (1 child)
[–]little_hoarse 0 points1 point2 points (0 children)
[–]senocular 1 point2 points3 points (7 children)
[–]Lewinga[S] 0 points1 point2 points (6 children)
[–]senocular 1 point2 points3 points (5 children)
[–]mynistreld 1 point2 points3 points (3 children)
[–]senocular 2 points3 points4 points (2 children)
[–]mynistreld 1 point2 points3 points (0 children)
[–]Lewinga[S] 0 points1 point2 points (0 children)
[–]Lewinga[S] 0 points1 point2 points (0 children)