开发者

Add a click event that happens after inline click event?

开发者 https://www.devze.com 2023-04-01 03:14 出处:网络
Using jQuery, I want to add a click event to a search button that happens after the event that is already tied to that button in the HTML (the other click event is in the tag\'s onclick event, it is N

Using jQuery, I want to add a click event to a search button that happens after the event that is already tied to that button in the HTML (the other click event is in the tag's onclick event, it is NOT added by javascript).

I've tried using .click(function() {..开发者_如何学运维.}); but that event will fire before the inline onclick event already on the button. How can I run my click event after the first one has completed?


One thing you can do is grab the inline events when the page loads and evaluate them before your custom click event code.

Something like this:

var events = $('#someAnchor').attr('onclick');
$('#someAnchor').removeAttr('onclick');

$('#someAnchor').click(function(){
    eval(events);
    alert("We came second");
})

Here's a quick example: http://jsfiddle.net/vkVuP/

0

精彩评论

暂无评论...
验证码 换一张
取 消