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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:42:01+00:00 2026-05-24T04:42:01+00:00

I once read that the following coding technique is considered bad: <a HREF="page.htm" onClick="alert(‘Hello

  • 0

I once read that the following coding technique is considered bad:

<a HREF="page.htm" onClick="alert('Hello World')">text link</a>

Basically, having these event handlers (like onClick) within the HTML tag is the wrong approach to use. What is the reason for this? What is this "bad" technique called? What is the "proper" way to do this?

  • 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-24T04:42:01+00:00Added an answer on May 24, 2026 at 4:42 am

    This is an inline event handler attribute. (+1 chjj’s answer for alternatives). It’s generally considered ‘bad’ for a number of reasons:

    • you’re mixing small pieces of JavaScript syntax inline with HTML syntax:

      • when you have lots of these, especially when you have lots of elements that all contain essentially the same bit of code, it’s harder to read and maintain the code;

      • you get nested-escaping horrors when you need to use special-to-HTML characters in your code:

    eg.:

    <a href="x.html" onclick="this.innerHTML= '&lt;em>I like &quot;fish &amp;amp; chips&quot;&lt;/em>';">
    
    • properties of the target element and all ancestor nodes become variables, potentially hiding your own variables of the same name. See this question for background on this surprising and almost always unwanted behaviour;

      • this introduces spooky incompatibilities as browsers have different DOM properties;

      • and future browsers introducing new properties will potentially break your code.

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

Sidebar

Related Questions

Once I read an MSDN article that encouraged the following programming paradigm (its not
I once read that one way to obtain a unique filename in a shell
I've often read that corporations will save millions once Internet Explorer 6 is finally
I always read that it is recommended to set objects to nothing, once I
This is one of those things that you read once, say aha! and then
Once I read in a statement that The language feature that sealed the deal
I read somewhere once that the modulus operator is inefficient on small embedded devices
The PHP documentation states that php://input can only be read once. In my application
I once read the following Perl code involving iterations. for my $j (0 ..
I once read about an open source database for postal codes with geolocation data

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.