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

  • Home
  • SEARCH
  • 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 65585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:58:10+00:00 2026-05-10T18:58:10+00:00

I have seen the following methods of putting JavaScript code in an <a> tag:

  • 0

I have seen the following methods of putting JavaScript code in an <a> tag:

function DoSomething() { ... return false; } 
  1. <a href='javascript:;' onClick='return DoSomething();'>link</a>
  2. <a href='javascript:DoSomething();'>link</a>
  3. <a href='javascript:void(0);' onClick='return DoSomething();'>link</a>
  4. <a href='#' onClick='return DoSomething();'>link</a>

I understand the idea of trying to put a valid URL instead of just JavaScript code, just in case the user doesn’t have JavaScript enabled. But for the purpose of this discussion, I need to assume JavaScript is enabled (they can’t login without it).

I personally like option 2 as it allows you to see what’s going to be run–especially useful when debuging where there are parameters being passed to the function. I have used it quite a bit and haven’t found browser issues.

I have read that people recommend 4, because it gives the user a real link to follow, but really, # isn’t ‘real’. It will go absolutely no where.

Is there one that isn’t support or is really bad, when you know the user has JavaScript enabled?

Related question: Href for JavaScript links: “#” or “javascript:void(0)”?.

  • 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. 2026-05-10T18:58:11+00:00Added an answer on May 10, 2026 at 6:58 pm

    I quite enjoy Matt Kruse’s Javascript Best Practices article. In it, he states that using the href section to execute JavaScript code is a bad idea. Even though you have stated that your users must have JavaScript enabled, there’s no reason you can’t have a simple HTML page that all your JavaScript links can point to for their href section in the event that someone happens to turn off JavaScript after logging in. I would highly encourage you to still allow this fallback mechanism. Something like this will adhere to "best practices" and accomplish your goal:

    <a href="javascript_required.html" onclick="doSomething(); return false;">go</a> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You need to 'free' the resident reference from the site… May 11, 2026 at 2:30 pm
  • added an answer First, to do your actual request You would set the… May 11, 2026 at 2:30 pm
  • added an answer If you are using any of the 'signed' APIs you… May 11, 2026 at 2:30 pm

Related Questions

My colleagues are attempting to connect BizTalk 2006 R2 via DB2/MVS adapter to a
In python, a module doesn't have to have a main function, but it is
I'm in the process of working on a user profile system for a website
I have this method Verify_X which is called during databind for a listbox selected

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.