Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove YUI delegated events?

Tags:

javascript

yui

I'm attempting to create a script for a platform that allows users to inject javascript. They are using YUI and specifically Y.one('body).delegate('click',...) to attach an event to a button. I would like to intercept this button but I cannot figure out how to stop, block, remove or otherwise prevent the event handler from firing.

Note: I don't have direct access to the handler returned by `Y.delegate()

So far I've tried

Y.detachAll('click');
Y.unsubscribeAll('click');
Y.one('body').detachAll('click');
Y.one('body').unsubscribeAll('click');
Y.one('.the-delegated-class').detachAll('click');
Y.one('.the-delegated-class').unsubscribeAll('click');

All to no avail. In fact the only success I've had is to completely remove and replace the body HTML which obviously takes all the event handlers with it as opposed to just the one I want to remove.

Any insights?

like image 985
KTastrophy Avatar asked Dec 31 '25 05:12

KTastrophy


1 Answers

Turns out one of my attempts was the correct method but my usage was wrong. I was (unknowingly) attempting to detach the event prior to it being attached in the first place.

That said in the case of: Y.one('body).delegate('click',...)

This works: Y.one('body').detach('click')

Though ideally you'd call detach direct on the EventHandle returned by the delegate call.

like image 194
KTastrophy Avatar answered Jan 02 '26 17:01

KTastrophy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!