How to block jquery on an element
I work with a rather complicated web UI that includes a lot of javascript, much of it implemented using jquery. It's my job to override the default javascript and to attempt to make customers happy with minor customizations here and there.
Sometimes there are bits of javascript that I know are in the UI, and which I need to override, but it can take me a long time to track them down. Once I've tracked them down, I haven't yet come up with a good way of blocking the default jquery even开发者_Go百科ts might be set up for the selection.
Is there an easy way to use jquery to make a selection and then define my own actions for it, or to block jquery on the selection completely?
For example, the default UI seems to define an onclick event for all links, which is preventing me from doing the seemingly simple task of adding target="_blank" to a link. I say "seems" because I haven't been able to find the javascript that is doing this, but I need to so that I can make the minor customization.
Check our jQuery's stopImmediatePropagation() . It prevents other event handlers from being called.
You could probably iterate through the objects and check each one for the expected vanilla javascript event handler:
$('a').each(function(){
if ($(this).get(0).onclick != '') {
$(this).get(0).onclick = '';
}
});
If you know the element that you want to stop events for, you can always use unbind()
. And then bind new event handlers to your element. You can specify the event type you want unbind or you can just call it without arguments and it will unbind all events attached to your element.
精彩评论