Get element on which currently called jQuery event handler is attached

In this post I am going to explain, how we can get the element on which currently called jQuery event handler is attached using a simple Event Object called  event.delegateTarget . This event object has been added to the jQuery version 1.7, so the examples below will not work with the previous versions of jQuery.
Continue reading

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

Slide toggle from right to left and left to right using jQuery UI

In this post I am going to explain, how we can slide a div element from right to left and left to right using jQuery UI toggle() method. Firstly, I will explain how we can do it using a simple example and finally, in the last demo section I will post two additional fiddle demos on the slide effect. 🙂
Continue reading

Styling alternate rows in HTML table using jQuery

In this post I am going to explain, how we can style the alternate rows of an HTML table using the power of jQuery. We can also do the same using the CSS fully but in case you prefer or are more interested to know, how to do it with jQuery and some CSS, here’s the demo. Let’s say we have a HTML markup like this:
Continue reading