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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:23:33+00:00 2026-05-24T10:23:33+00:00

Suppose I need to write an onclick handler in an attribute , like this:

  • 0

Suppose I need to write an onclick handler in an attribute, like this:

<a href='#' onclick='DoSomething(); event.stopPropagation(); return false;'>
    ...</a>

I know this is bad form, but suppose for the moment that I have to use an attribute.

Unfortunately event is not defined. I tried e and that is not defined either. Is there any way to access the event object inside the attribute, or any other way to stop the event propagation?

  • 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-24T10:23:34+00:00Added an answer on May 24, 2026 at 10:23 am

    Where you get the event object depends on the browser. Some (all?) IE versions put it in window.event but everyone else passes it as an argument. So, you end up having to do a silly little dance like this:

    function DoSomething(event) {
        event = event || window.event;
        event.stopPropagation();
        // Do useful work.
        return false;
    }
    

    And then set up the onclick like this:

    <a href="javascript:void(0)" onclick="DoSomething(event)">
    

    I also switch to javascript:void(0) so you don’t have the usual “# interpreted as an in-page fragment” problems.

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

Sidebar

Related Questions

I need to write a java script. This is supposed to validate if the
Suppose I have a simple table, like this: Smith | Select Jones | Select
Suppose I have a MySQL table called MyTable, that looks like this: +----+------+-------+ |
I need to write the content of an array into a file. Let's suppose
Suppose it is a long article (say 100,000 words), and I need to write
Suppose I need to write many images to iPhone file system. And I need
I need to write an excel-like grid that can have a lot of cells
Suppose I have a ViewModel with 100 props. Currently I need a one handler
Suppose you need to run a program on the world’s fastest supercomputer which will
Suppose I need to break out of three or four nested for loops at

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.