1) $ ("selector"). Map (Callback (index,domelement)); The. Map () method is used to pass each element of the currently matched element collection into the callback function (callback) and returns a new jquery object, which is equivalent to reorganizing the matching collection contents by this method. Where index is the element index, DomElement is the jquery object corresponding to the current index. 2) $ ("selector"). not (expr); The. Not () method is used to remove the specified collection from the matching selector element collection, and expr can be a selector (selector) or a function, and if the selector removes the set of expr in the selector collection; If expr is a function, The jquery object corresponding to the current index is removed only if the function returns True. 3) $ ("selector"). Add (Selector1[,context]); The. Add () method adds a SELECTIOR1 element to the collection of matched elements, contrary to the function of the not () method. Where selector1 can be a jquery object, a DOM object, and an HTML tag. The optional parameter context is where you specify the context to insert 4) $.each (Collection,callback (indexinarray,valueofelement)); The. each () method iterates over the collection array, where callback is the callback function Note: This method differs from $ ("selector"). each (function () {}) method can traverse all arrays, while $ (" Selector "). each (function () {}); only a jquery object array can be traversed.
var array = [1,2,3,4]; $ (array). Each (function (index) { alert ( (this);}); $.each (array,function (index) { alert (this);});
5) $.contains (container,contained); The. Contains () method is used to detect if a contained object is contained in a container object, and returns False if it contains true.
$.contains ($ ("div") [],$ ("P") [0]); // detects if the first P tag is within the first div tag.
6) $.isemptyobject (object); The. Isemptyobject () method is used to determine whether an object is empty (null for objects that do not contain any properties), or null to return True
$.isemptyobject ({}); // $.isemptyobject ({foo:"bar"}); // returns false
7) $.extend (TARGET,OBJECT1); The. Extend () method merges the contents of two or more objects into the first object target to implement an extension of the first object and return the modified object.
$.extend ({foo:"aa"},{bar:"bb"}); // The result is: {foo: "AA", bar: "BB"}
8) $.browser//.browser Property This property can get the version information of the current browser
if ($.browser.msie) alert (" browser is ie:"+$.browser.version); if ($.browser.mozilla) alert (" browser is Firefox:"+$.browser.version);
9) $.support//.support Property This property is used for Warriors with different browser features and bug sets. The parent () method allows us to search the DOM tree for the parents of these elements, traversing a single level along the DOM tree. The parents () method allows me We search the DOM tree for the ancestor elements of these elements and construct a new JQuery object from the matching elements that are arranged in the order of the nearest parent element. The elements are returned in order from the nearest parent element.
$ (e.currenttarget). Parent ("ul")// View parent element, satisfy conditional return result, not satisfy return to empty $ ( E.currenttarget). Parents ("ul") [0]// return all ancestor elements satisfying the condition, [0] Represents the closest result to getting a distance
11) Determine the position of the array element
$ (". Js-groupstarresultlist:visible"). Find (". Flex-control-nav Li a "). Index ($ (". Flex-active"));
12)in jquery 1.4.2, the delegate and Undelegate options //introduced instead of live because they provide better context support
For example, in the case of table, you used to
//. Live ()$("Table"). each (function () {$ ("TD", This). Live ("Hover", Function () {$ ( This). Toggleclass ("Hover"); }); }); //now with$("Table").Delegate("TD","Hover", Function () {$ ( This). Toggleclass ("Hover"); });
13) Cloning an element
var cloned = $ ('#somediv'). Clone ();
14) How to use. Siblings () in jquery to select sibling elements
//don't do that$('#nav Li'). Click (function () {$ ('#nav Li'). Removeclass ('Active'); $( This). AddClass ('Active'); }); //An alternative approach is $('#nav Li'). Click (function () {$ ( This). AddClass ('Active'). Siblings (). Removeclass ('Active'); });
15) Check whether the image has been fully loaded in
$ ('#theImage'). attr ('src'image.jpg ' ). Load (function () { alert ('thisImage has Been Loaded'); });
Common methods of jquery