.on() current and future elements problem

11 views
Skip to first unread message

Bryan Hughes

unread,
Oct 16, 2017, 3:03:09 PM10/16/17
to gwtquery
I'm using GWT and GwtQuery to create a javascript file to track some analytics.

I want to bind handlers to elements with certain data- attributes, they may or may not be present onModuleLoad().

I tried:
 
$(document).on("click", "body * img[data-im-lookingfor]", new Function() {...});
$(document).on("click", "img[data-im-lookingfor]", new Function() {...});
$(GQuery.document).on("click", "img", new Function() {...});

But it will not bind to anything. Looking the source code for .on, when a selector is passed it will create a delegate behind the scenes.

What does work, but only for elements present onModuleLoad():

$("img[data-im-lookingfor]").on("click", new Function() {...});

I'm looking for a way to bind to all current and future elements, whether created in plain javascript or inside the GWT/GQuery Module.

Any suggestions.

Thanks, --B
Reply all
Reply to author
Forward
0 new messages