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

This is the output: [ { 0: 1, cat_id: 1, 1: Hello World!, post_title:
Boy, this one is really weird. I expect the following code to print 1990,
i found this code online and im trying to compile it, but gcc keeps
I'm a JavaScript newbie working on a website and I've run into an issue
I'm just getting started with Python/Pandas and put together the following code to plot
Ok, we aren't in the mid-1980s any more, but anyway. Are there any fax
I'm implementing the Verhoeff algorithm for a check digit scheme, but there seems to
I am taking a peek at Dive Into HTML5 . It seems nice and
There's a file with such structure: companyname1;shortname1;identification1;01.01.1980 companyname2;shortname2;identification2;01.01.1987 companyname3;shortname3;identification3;01.01.1990 companyname4;shortname4;identification4;23.01.1995 I want to put
How can I convert a JIS X 208 encoded string into UNICODE in C++?

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.