Bind events to dynamically created elements using jQuery

While writing code in jQuery, we sometimes need to create HTML elements dynamically. But the problems starts occurring when the events that we have already binded to the existing HTML elements, does not works in the same way for the newly created elements. So, lets say we have existing DIV and we have a click event binded to it. Now, when we click on this DIV, we get an alert. After that, we add one more DIV to the page dynamically, but on clicking on this new DIV there is no alert coming. So, what is the problem here? Why is the click event not working for this new DIV? Let’s look into this problem in details.
Continue reading


jQuery Trick #2: Global search flag in Regular Expression

In this post I am going to explain, the usage of the global search flag while working on a Regular Expression. We will find out how this simple trick can help us. By the way, this is my second post in the series of jQuery Tricks .
Continue reading