Access to a fixed element when using $ (fixedElem) .on (event, dynamicElem, func)

If you have dynamic elements that need listeners, you are doing something like this:

$(fixedElem).on(event, dynamicElem, function(e){
    // Here 'this' is the dynamicElem that the event fired on
});

How can I get the fixedElemlistener to be added?

+4
source share
1 answer

You can use event.delegateTarget :

$(fixedElem).on("event", "dynamicElem", function(e) {
    console.log(e.delegateTarget);  // Here, fixedElem will be logged.
});
+1
source

Source: https://habr.com/ru/post/1624977/


All Articles