How to attach an event to a particular type of element for the whole life of the page in jQuery- .live()

To attach an event to a particular type of element for the whole life of the page, live() method can be used. The event attached using live() works for all similar type of elements even created after this method is called. $("#pLive").live("click", function () { $(this).before("<p>New paragraph added</p>"); $(this).after("<p id=’pLive’ style=’color:green;’>New paragraph added – this […]
Continue reading…

Enjoyed this post? Share it!

 
 

How to attach multiple events at once to an element in jQuery?

To attach multiple events to an element, write the events separated by space. function bindAction() { alert("I am active !"); } $("#btnBindAction").click(function () { $("#btnAction").bind(’mouseenter click’, bindAction).val("Mouse hover Now and then click"); }); $("#btnUnbindAction").click(function () { $("#btnAction").unbind(’mouseenter click’, bindAction).val("Simple button"); }); In the above code, when you click on the “btnBindAction” button, mouseenter as well […]
Continue reading…

Enjoyed this post? Share it!

 
 

How to attach and detach an event to and from an element in jQuery? – .bind() & .unbind()

To attach and detach an event to and from an element, bind() and unbind() method can be used respectively. function bindAction() { alert("I am active !"); } $("#btnBindAction").click(function () { $("#btnAction").bind(’click’, bindAction).val("Click Now"); }); $("#btnUnbindAction").click(function () { $("#btnAction").unbind(’click’, bindAction).val("Simple Button"); }); In above code snippet I have declared a function called “bindAction” that will be […]
Continue reading…

Enjoyed this post? Share it!

 
 

How to attach a blur event to an element in jQuery- .blur()

jQuery events methods are used to specify the behavior of the html element when user interacts with the web page contents. To attach blur event to an element, blur() method can be used that fires when the element loses focus. $("#txtBlur").blur(function () { alert("blur handler called"); }); Above code will execute when user will leave […]
Continue reading…

Enjoyed this post? Share it!

 
 

How to wrap an element from a specific element in jQuery? – .wrap()

To wrap an element from a specific element, wrap() method can be used. $("#divP").wrap("<div id=’divScroll’ style=’height:100px;width:300px;overflow:scroll;’></div>"); Above code will wrap the “divP” with the specified div html tag. <p id="divP" style="height:300px;width:500px;background:#efefef;"> This is looking nice. </p> After wrapping, above code snippet will become <div id="divScroll" style="height:100px;width:300px;overflow:scroll;"> <p id="divP" style="height:300px;width:500px;background:#efefef;"> This is looking nice. </p> </div>
Continue reading…

Enjoyed this post? Share it!