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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:25:18+00:00 2026-06-08T04:25:18+00:00

This is my html code <a href=# onclick=return clickHandler()>Hit</a> This is my javascript file

  • 0

This is my html code

<a href="#" onclick="return clickHandler()">Hit</a>

This is my javascript file

function clickHandler(evt) {
    var thisLink = (evt)?evt.target:Window.event.srcElement;
    alert(thisLink.innerHTML);
    return false;
}

But when i click the Hit Link, it redirects.

  • 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-06-08T04:25:20+00:00Added an answer on June 8, 2026 at 4:25 am

    To tie both of the very-correct answers together, what’s happened is you’ve inlined a function where you’ve written onclick="return runFunction();"

    If you look at that, what it’s really doing is going like this:

    var link = document.getElementById("myLink");
    
    link.onclick = function () { runFunction(); };
    

    See the problem?

    My runFunction is being called without any event object passed in, at all.
    …which means that var thisLink = (evt) ? is going to return false, which means that it’s going to try to run in oldIE-mode.

    By writing onclick="runFunction", that’s the same as saying:

    link.onclick = runFunction;
    

    Which means that when the onclick event happens, runFunction will be called, and in W3C-compliant browsers, it will be sent an event object.

    Which is why that solution works.

    The best way to avoid a lot of this confusion is to deal with JavaScript from inside of JavaScript, and to deal with HTML inside of HTML, so that you don’t have to worry about how strings translate into code.

    Now, to get all of this to work, AND prevent redirection, you want to do this:

    for W3C browsers (the ones that pass the event parameter):

    function runFunction (evt) {
    
        // stops the default-action from happening
        // means you need to find another way to fire it, if you want to later
        evt.preventDefault();
    
    
        // stops higher-up elements from hearing about the event
        // like if you stop a submit button from "clicking", that doesn't stop the form
        // from submitting
        evt.stopPropagation();
    
        //the oldIE versions of both of these are
        event.cancelBubble = true;
        event.returnValue = false;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having such an html: <a class=someclass href=some/url/absolute/or/relative>Blah</a> ... along with such javascript: $(a.someclass).onclick(function() {
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
Hello there i got some code here; <script type=text/javascript> $(function(){ var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/8BCDD04DE8F771B2?v=2&alt=json&callback=?';
I have this html code that I need to parse <a class=sushi-restaurant href=/greatSushi>Best Sushi
i have this html code <table style=width: 100%;> <tr> <td> ID </td> <td> <input
I have this HTML code for radios: <input type='radio' name='a_27' value='Yes' id='a_27_0' /> <input
I have this html code that i want to edit with jQuery. Here is
I have this HTML code: <div class='com_box'> <div class='com_box_c'> <div class='com_box_info'> <a id='quote'>quote</a> </div>
I have this HTML code: <div id=main> <div id=dv_7>...</div> <div id=dv_1>...</div> <div id=dv_8>...</div> <div
I have this HTML code which simulates a dropdown multi-checkbox <div> <div class=select> <span>Select

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.