Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I put a Semicolon (;) when I use onclick=""

Should I put a Semicolon (;) when I use onclick=""?

<p onclick="closeLightBox();">Click<p> 

or:

<p onclick="closeLightBox()">Click<p> 
like image 913
faressoft Avatar asked Feb 10 '11 21:02

faressoft


People also ask

Should Javascript functions end with semicolon?

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.

Which tag can use onclick?

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.

Why Onclick works only once?

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.


1 Answers

The semicolon in this position, is valid, but not mandatory.

like image 166
ocodo Avatar answered Sep 29 '22 20:09

ocodo