jQuery .live() vs .on() method for adding a click event after loading dynamic html

If you want the click handler to work for an element that gets loaded dynamically, then you set the event handler on a parent object (that does not get loaded dynamically) and give it a selector that matches your dynamic object like this: $(‘#parent’).on(“click”, “#child”, function() {}); The event handler will be attached to the … Read more

How do you run your own code alongside Tkinter’s event loop?

Use the after method on the Tk object: from tkinter import * root = Tk() def task(): print(“hello”) root.after(2000, task) # reschedule event in 2 seconds root.after(2000, task) root.mainloop() Here’s the declaration and documentation for the after method: def after(self, ms, func=None, *args): “””Call function once after given time. MS specifies the time in milliseconds. … Read more

How do I attach events to dynamic HTML elements with jQuery? [duplicate]

I am adding a new answer to reflect changes in later jQuery releases. The .live() method is deprecated as of jQuery 1.7. From http://api.jquery.com/live/ As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live(). For jQuery 1.7+ … Read more