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 678535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:09:37+00:00 2026-05-14T01:09:37+00:00

In the 1990s, there was a fashion to put Javascript code directly into <a>

  • 0

In the 1990s, there was a fashion to put Javascript code directly into <a> href attributes, like this:

<a href="javascript:alert('Hello world!')">Press me!</a>

And then suddenly I stopped to see it. They were all replaced by things like:

<a href="#" onclick="alert('Hello world!')">Press me!</a>

For a link whose sole purpose is to trigger Javascript code, and has no real href target, why is it encouraged to use the onclick property instead of the href property?

  • 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-05-14T01:09:38+00:00Added an answer on May 14, 2026 at 1:09 am

    The execution context is different, to see this, try these links instead:

    <a href="javascript:alert(this.tagName)">Press me!</a> <!-- result: undefined -->
    <a href="#" onclick="alert(this.tagName)">Press me!</a> <!-- result: A -->
    

    javascript: is executed in the global context, not as a method of the element, which is usually want you want. In most cases you’re doing something with or in relation to the element you acted on, better to execute it in that context.

    Also, it’s just much cleaner, though I wouldn’t use in-line script at all. Check out any framework for handling these things in a much cleaner way. Example in jQuery:

    $('a').click(function() { alert(this.tagName); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to configure VS2010 to use different color schemes for different
I am using jQuery to get visitor's location via their IP address. There's a
Evening :) I have a little problem... As you can see in my code
I am working on an ASP.NET project, and it is very frustrating how poor
I have a MySQL DATETIME field that holds the date of birth of a
I want to be able to test whether a value is within a number
I have been working with C# for many years, since beta. I am having
I'm developing an app in Python for Google App Engine. When I run the
I'm new to Python and have what is probably a very basic question about
I downloaded a jquery collapsible panel script (used as a menu), which I've got

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.