im getting confused about the different between those functions on the onclick ?
and which is better ? and what they mean if they are differents .
onclick = "return func()"
onclick = "return func();"
onclick = "javascript: func()"
onclick = "javascript: func();"
onclick = "func()"
onclick = "func();"
onclick = "return true"
any explanations will be much appreciated .
and if there is more , would like to know it also
There is no difference between
return func()andreturn func();The semicolon will be added on the fly if it isn’t there. Same obviously goes for the other examples.return func()invokesfunc()and returns (the “return” part is a little complicated, but it involves bubbling and it overrides the default behavior for clicks, I believe. Returningtruetells the browser to invoke the default behavior (like going to a link’s target, for example), and returning false disables the default behavior. I’m not entirely sure what it’ll do if it returns anything else.javascript:func()is (almost) the same asfunc()— but it’s an outdated way to do it. Don’t use this.func()is almost the same as the others, but it can cause some problems with bubbling and default behavior. Usually, you’ll want to specify eitherreturn true;orreturn false;return truedoesn’t do much of anything. It just tells the browser “do what you were already going to do.” Returning false, on the other hand, would disable default behavior.In conclusion, the first six will basically do the same thing, the seventh will just invoke the default behavior.