1

Here's what I'm trying to do :

I have a page with some links. Most links have a function attached to them on the onclick event.

Now, I want to set a css class to some links and then whenever one of the links is clicked I want to execute a certain function - after it returns , I want the link to execute the onclick functions that were attached to it.

Is there a way to do what I want ? I'm using jQuery if it makes a difference.

Here's an attempt at an example :

$("#link").click(function1); $("#link").click(function2); $("#link").click(function(){ firstFunctionToBeCalled(function (){ // ok, now execute function1 and function2 }); }); // somehow this needs to be the first one that is called function firstFunctionToBeCalled(callback){ // here some user input is expected so function1 and function2 must not get called callback(); } 

All this is because I'm asked to put some confirmation boxes (using boxy) for a lot of buttons and I really don't want to be going through every button.

1

4 Answers 4

1

If I understand you correctly, is this wat you wanted to do..

var originalEvent = page.onclick; //your actual onclick method page.onclick = handleinLocal; //overrides this with your locaMethod function handleinLocal() { ...your code... originalEvent (); // invoke original handler } 
Sign up to request clarification or add additional context in comments.

Comments

0

I would use jQuery's unbind to remove any existing events, then bind a function that will orchestrate the events I want in the order I want them.

Both bind and unbind are in the jQuery docs on jquery.com and work like this...

$(".myClass").unbind("click"); // removes all clicks - you can also pass a specific function to unbind $(".myClass").click(function() { myFunctionA(); myFunctionB($(this).html()); // example of obtaining something related to the referrer }); 

2 Comments

What about the onclick function that was attached to the element?
Exactly, the thing is that every link has a different method/methods - and the mechanism needs to be generic - so I can apply it to any element.
0

An ugly hack will be to use the mousedown or mouseup events. These will be called before the click event.

1 Comment

Yes, but when that gets clicked, I need to execute a function and on that functions callback - continue to run all it's click attached functions.
0

If you can add your event handler before the rest of handlers, you could try to use jQuery's stopImmediatePropagation

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.