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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:49:55+00:00 2026-05-24T00:49:55+00:00

read final edit for solution I’m try update the onclick function of a link

  • 0

read final edit for solution

I’m try update the onclick function of a link using jquery.

example would be best to explain:

html

<a href='' id='one_click' onclick='do_things_here("fighter","bitter",2)'>first clicker</a>

<a href='' id='two_click' onclick='do_things_here("abc","xyz",1)'>second clicker</a>

js (something like this – I don’t this is actually correct logically speaking)

function do_thing_here(data, info, source){

  *//things happen here*

  $('#two_click').click(function() {
    do_things_here(data,info,source)
    return false;

    });


}

That doesn’t work as it goes into a recursive loop as do_things_here gets set off when resetting the onclick on ‘two_click’.

edit

I’ve tried to set a reset flag to prevent do_things_here running on re-setting the onclick

function do_thing_here(data, info, source,reset){
      if (reset){
           return false;
      }


      *//things happen here*

      $('#two_click').click(function() {
        do_things_here(data,info,source,true)
        return false;

        });


    }

but that did seems a bit hack-ish and I don’t think it worked, I still had issues – I’ll try to do it again and see what the issues where.

I’ve tried unbinding and removeAttr/attr in an attempt to reassign as explained here

JavaScript: changing the value of onclick with or without jQuery

those methods do not seem to work in all browsers

  • Using jQuery attr("onclick", js) doesn’t work with both Firefox and
    IE6/7.
  • Using setAttribute(“onclick”, js) works with Firefox and IE8,
    but not IE6/7.
  • Using onclick = function() { return eval(js); } doesn’t work
    because you are not allowed to use return is code passed to eval().

I’ve tried clearing out the onclick function in the html so nothing is set as default but that didn’t have any effect.

I can simply reset/rejig the link as follows

<span id='change_two'><a href='' id='two_click' onclick='do_things_here("abc","xyz",1)'>second clicker</a></span>

and then

 function do_thing_here(data, info, source){

      *//things happen here*

      $('#change_two').html("<a href='' id='two_click' onclick='do_things_here('+data+','+info+','+soutce+')'>second clicker</a>");


    }

or something similar but I’m wondering if there is a better cleaner way to do it?

—-edit:solution explained—-

just for those googling on to this page:

if you set the onclick via html you need to removeAttr ($(this).removeAttr('onclick'))

if you set it via jquery (as the after the first click in my examples above) then you need to unbind ($(this).unbind('click'))

Then you simply rebind with bind ($(this).bind('click',function(event){//the code/function call})))

//important – removeAttr: use ‘onclick’ and unbind: use ‘click’ – I think that was my main problem!

wasn’t sure if I should post this as an answer as the solution was right there in my question! Sorry folks for the brain failure.

I know in the question it states “not using unbind/removeAttr” – that was because I thought it was not working with those functions – but that was only due to the usage of the different functions.

  • 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-24T00:49:56+00:00Added an answer on May 24, 2026 at 12:49 am

    Not sure what you are trying to achieve, but to unbind a click event, just use $(this).unbind(‘click’)

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

Sidebar

Related Questions

I read somewhere that interfaces can have member variables. Static final constants only, can
I've just read tutorial about enums and have one question. I've studied example: public
I have read several theads, blogs and forum but I didn't find the solution
Noob here again. I've followed the example given by Google Dev (and read a
I read this PHP RegEx page , but either I'm missing something, misreading something,
Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service
I read somewhere once that the modulus operator is inefficient on small embedded devices
I read the Git manual, FAQ, Git - SVN crash course, etc. and they
Please read the whole question. I'm not looking for an approach to managing multi-lingual
I read in this article that a company has created a software capable of

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.