click() vs bind() vs live() vs delegate()
click() vs bind() Bind an event handler to the "click" JavaScript event, or trigger that event on an element.First, .click(function) is literally a shortcut for .bind('click', function), they are equivalent. Use them when binding a
click() and dblclick()
click() : Fire when mouse single click on the matched element. dblclick() : Fire when mouse double clicks on the matched element. Example : $('#singleClick').click(function(){ $('#singleClick').css("border", "1px solid red"); }); $('#doubleClick').dblclick(function(){ $('#doubleClick')..css("border", "1px solid blue");
.empty() vs .remove() vs .detach()
jQuery provides various methods to remove elements from DOM. These methods are .empty() .remove() and .detach() .empty(): This method removes all the child element of the matched element from DOM. .remove(): This method used when
.add() Method
.add() Add elements to the set of matched elements. HTML: <p>Hello</p><span>Hello Again</span> JQUERY: $("div").css("border", "2px solid red") .add("p") .css("background", "yellow"); This JQ will, Step : 1ย find the div and apply the red to the
addClass() and removeClass()
Jquery .addClass() and .removeClass() used to add or remove CSS class dynamically in the Html element. For Example .addClass() $(โ#p1โฒ).addClass(โcssclass1โ); Add a โcssclass1โ css class to elements that contain id of โp1โณ. .removeClass() $(โ#p1โฒ).removeClass(โcssclass1โ); Remove
.find() vs .filter()
Both filter() and find() methods are very similar, except the former is applies to all the elements, while latter searches child elements only. find() searches the descendants of the elements in the matched set. filter()
Difference Between jQuery Text() And HTML()
ย In this post you will learn about the difference between jQuery text and HTML. .html() - This jQuery function gets/sets the HTML of any element. .text()- This jQuery function gets/sets the text (innertext) of
.append() VS .html()
.append() and .html() is the most usefull method in jQuery.But these are far different from one another, .append() add some value with the existing one. whether .html() do the same but it removes the old