1

Why some developers use,

<input type="button" onClick="javascript:function-name()">

instead of

<input type="button" onClick="function-name()">

Please help me to solve this matter.

1
  • Totally legit question, but function-name() won't work, the caracter - is not accepted in any JS name, it means "minus". Your function name is equivalent to function - name(). You should write function_name() or functionName(). Commented Mar 30, 2015 at 6:52

1 Answer 1

1

Because they probably just don't know better and think they have to use javascript: whenever they use JS in an HTML attribute.


In an event handler attribute, javascript: is nothing but a label and is entirely useless.

However, it is necessary in href attributes, but it has a completely different meaning: It is a pseudo-protocol, which tells the browser to interpret the remainder of the "URI" as JavaScript.

(not to mention that using JS inside an href is considered bad practice)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.