How to split the attribut “class” name in the html element
How to split the attribute "class" name in the html element HTML : <div id="divUserDetails" class="red"> JQEURY : $(document).on("click", "#divUserDetails", function() { var userColor = $(this).attr('class') == null ? "No User Color Found" : $(this).attr('class');
How to get the top and left positon of clicked td/div
How to get the top and left positon of clicked td/div Jquery $(document).on("click", "#tbUserDetails", function() { var getclickTop = $(this).offset().top; var getclickLeft = $(this).offset().left; } Explanation: .on method is used for dynamically created table using
removeAttr() Method
.removeAttr() Remove an attribute from each element in the set of matched elements. HTML : <table border="1"> <tr><td>This is first table</td></tr> </table> JQUERY: $(document).ready(function() { $("table").removeAttr("border"); }); OUTPUT DOM : <table> <tr><td>This is first table</td></tr>
attr() Method
attr() : The attr() method sets or returns attribute values of selected elements. Getting attribute JQUERY : 1 alert($("#img1").attr("href")); From above JQ, the message box will show the link of img1(which element having id as
clone() Method
clone() Create a deep copy of the set of matched elements. We can use clone copy in to two ways,clone()/clone(true).It also support a boolean parameter to indicate whether need to copy the event
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