views:

53

answers:

3
+1  Q: 

Jquery/Javascript

Good morning peoples.

I have a bit of a slight jQuery question/problem that I am not sure how to tackle.

I have a click handler bound to varying classes on some anchor tags (which works great). I have now come to a page that needs an extra handler on the same anchor tags so I decided to use some namespacing to get the desired result. The trouble with the namespacing is that it is called before the original click handler and creates problems with the first handler. The error is raised due to the first handler requiring an element to exist to continue in the function but the namespaced click handler removes the element before so it errors out.

Does anyone know if one can tell namespaced handlers to execute After the original handler or would I have to completely re-write the script and perhaps extend it on this one (and only) page to have the funcitonality work as I would like.

Thanks in advance.

Alex

A: 

It's easier to add a classname to the anchors on the page that events are bound on and check that in my function..

Sorry for any time wasted

Alex
A: 

If you bring the handler out into a separate function, you can call the original handler from the other handler.

function handler() {
  // original event handler code
};

$('#originalTarget').click(handler);

$('#otherTarget').click(function() {
  // code to do anything specific to this handler
  handler();
}
EMMERICH
A: 

You can assign more than one handler:

// general handler
$('a.linkclass').click( function(){
  doThis();
});

// specific handler on the page in question
$('#specificlink').click( function(){
  doSomethingExtra();
});
Ken Redler