0 votes
1 view
in Web Technology by (47.8k points)

I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on the mouse on/off.

This happens on the page ready and works just fine.

The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.

I have found this plugin (jQuery Live Query Plugin), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.

1 Answer

0 votes
by (107k points)

For event binding on dynamically created elements you can use jQuery.fn.on see the code below:-

$(staticAncestors).on(eventName, dynamicChild, function() {});

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !