Should I put a Semicolon (;
) when I use onclick=""
?
<p onclick="closeLightBox();">Click<p>
or:
<p onclick="closeLightBox()">Click<p>
No. You don't need semicolons when defining a function like that. It's not strictly necessary, but you may want to use them, especially if you put the function on one line. The first way defines a function, but the second way assigns a function to a variable, and thus is a statement.
As per my knowledge, we can add click events on almost all elements, but per the HTML standard, we should add click events only on <a> or <button> tags. Are there any other HTML elements we should use to trigger a click event? You can have an onclick event on any tag as per HTML5 specification.
onclick event works only once in arctext script. Here is the code in Codepen: http://s.codepen.io/Noureddine/debug/JbbBQX. Well you only execute the random part once. If you want it to execute again, you need to move that logic inside.
The semicolon in this position, is valid, but not mandatory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With