Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8359243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:05:09+00:00 2026-06-09T11:05:09+00:00

What is the difference between the following? onClick=javascript: function(‘value’); onClick=function(‘value’); When do I use

  • 0

What is the difference between the following?

  1. onClick="javascript: function('value');"
  2. onClick="function('value');"

When do I use the javascript: before the function call, and why?

Can I call the function without using javascript: prefix?

Please help me understand the difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:05:11+00:00Added an answer on June 9, 2026 at 11:05 am

    In an element’s inline event handler, like onclick, onchange, onsubmit, etc., you do not need the javascript: prefix – the reason you often see it is because people confuse it with the href syntax that I explain below. It doesn’t cause an error – I believe it is interpreted as a label – but it is unnecessary.

    It doesn’t matter whether you want to call a function or run a “simple” JS statement, either way don’t include javascript: – that is, all three of these are valid:

    onclick="doSomething('some val');"
    onclick="return false;"
    onclick="doSomething(); doSomethingElse(); return false;"
    

    If you are using inline event attributes don’t use the javascript: prefix.

    (I say “if you are using inline event attributes” because this practice is really outdated: it is better to assign the event handlers using JS in a script block.)

    You only need the javascript: prefix when you want to run JavaScript from an <a> element’s href attribute like this:

    <a href="javascript: someFunc();">Whatever</a>
    

    That is because the browser normally expects the href to contain a URI, so the javascript: prefix tells it to expect JS code instead. However, I don’t recommending doing that because the page won’t work for people who have JS disabled. Better to include an href that directs the user to a page telling them to enable JS, and include an onclick to do the JS functionality:

    <a href="/enableJS.html" onclick="doSomething(); return false;">Whatever</a>
    

    That way the link does something useful for users whether they have JS enabled or not. The return false at the end of the click handler prevents the default behaviour for a click (which would be to navigate to the specified URL).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know the difference between following javascript functions. Can someone help whats
What's the difference between following relative paths? <script type=text/javascript src=../Scripts/jquery-1.2.6.js></script> <script type=text/javascript src=../../Scripts/jquery-1.2.6.js></script> <script
Question 1 Can anyone tell me if there is any difference between following 2
What is difference between the following two function definitions? A 2D array is being
what is the difference between following function declarations, which create and return the array
What's the difference between the following three .htaccess rules and when to use each,
Please highlight the difference between the following function declarations: void (*p) (void *a[], int
What is the difference between the following function definitions? 1: $(function () { //stuff
What is the difference between the following set of pointers? When do you use
Can anybody tell me the effective difference between the following connection strings: <add key=ConnectionString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.