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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:22:23+00:00 2026-05-20T18:22:23+00:00

I have a link which has an onclick attribute, and there is a toggle

  • 0

I have a link which has an onclick attribute, and there is a toggle event that I bind to the link (I know I’m committing a sin here by mixing these two, but there is nothing I can do about it.)

Now to this background, I have 2 scenarios:

  1. The user clicks on the link – The order of execution of events is :- onclick first, then the toggle event bound via jQuery
  2. Fire the click event via jQuery – The order of execution here is different, the bound event fires first then the onclick.

Something goes horribly wrong because of these 2 scenarios and the flipping of the order. I need the bound events to run first before the onclick. Is there any better way to do this than removing the onclick attribute on init and saving them to the link via .data() and then handling through the toggle event?

Another thing that I need to take care of (life is complicated), the link can be toggled through the querystring. i.e. if the user comes in from another page via another link, there will be a querystring parameter with the link id, which is read by another JavaScript function that does scenario 2 mentioned above.

So if the onclick is to be removed, it will have to be done on init.

What can I do to untangle this mess?

  • 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-20T18:22:23+00:00Added an answer on May 20, 2026 at 6:22 pm

    What is so wrong to remove the .onclick function and re-bind it afterwards (after you bound all your methods which should fire before) ?

    HTML

    <div id="foo" onclick="inline();">click me</div>
    

    Javascript

    function inline() {
        alert('I was bound through onclick=');
    }
    
    $(function() {
        var $foo = $('#foo'),
            stored = $foo[0].onclick;
    
        $foo[0].onclick = null;
    
        $foo.bind('click', function() {
            alert('I was bound via jQuery');
        });
        $foo.bind('click', stored);
    });
    

    After that code, the order of alerts would be:

    'I was bound via jQuery'
    'I was bound through onclick='
    

    Demo: http://jsfiddle.net/3MKWR/

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

Sidebar

Related Questions

I have a link that I dynamically create which looks something like the following:
I have an anchor that doesn't go anywhere but has an onclick (e.g. <a
lets say i have a custom widget which has a ClickHandler. Here's the example:
I have a grid which has a link to next page and I have
I have the following JavaScript code: Link In which the function makewindows does not
I have a link in a pdf-document (PDF1), which is embedded in a browser
I have written an AppleScript which when supplied with a Windows network link, will
I have a database which is in Access (you can get it link text
I have multiple rows in a table, in one of which is a link
Does anyone know, or have a link to an article or a step by

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.