On the description and application _jquery of jquery advanced method

Source: Internet
Author: User

1.addBack ()

A. Third-item's Li next several neighboring nodes (including Third-item)

$ ("Li.third-item"). Nextall (). Addback (). 
 CSS ("Background-color", "Red"); 

B. Similar to the end () method, the Div.after-addback and P elements are selected, and end is selected with the Div.after-addback element

$ ("Div.after-addback"). Find ("P"). Addback (). addclass ("background"); 

2.callback.fire ()

Call foo function via argument

var foo = function (value) { 
  console.log ("foo:" + value); 
} 
var callbacks = $. Callbacks (); 
Callbacks.add (foo); 
Callbacks.fire ("Hello"); 
Callbacks.fire ("World"); 

3.callback.lock ()

Lock the callback function list, this method cannot accept any arguments.

var foo = function (value) { 
 console.log ("foo:" + value); 
var bar = function (value) { 
 console.log ("bar:" + value); 
}  
var callbacks = $. Callbacks (); 
Callbacks.add (foo); 
Callbacks.fire ("Hello"); The output "Foo:hello" 
callbacks.lock ();///The Foo method cannot be invoked thereafter unless $. Callbacks ("Memory"), you can add a function 
Callbacks.fire ("World");//No Call to Foo method 
Callbacks.add (bar);////When callbacks assignment is $. Callbacks ("Memory"), creates a callback object, uses the memory identifier, can add a function 
Callbacks.fire ("World");/output "Bar:hello" 

4.defered.promise ()

Returns another deferred object on the original deferred object

$ (function () { 
  $ ("Input[type=button]"). Click (function () { 
    $.ajax ({ 
      URL: "validate.html", 
      type: " POST ", 
      dataType:" JSON " 
    }). Done (function (data) { 
      alert (DATA.A); 
    }). Fail (function () { 
      alert ("error"); 
    }) 
  ; 
       
  var DTD = $. Deferred (); 
  var wait = function (DTD) { 
    var tasks = function () { 
      alert (completed!) "); 
      Dtd.resolve (); Change the execution state of the deferred object 
    };  SetTimeout (tasks,5000); 
}; 
Dtd.promise (wait); 
Wait.done (function () {alert ("Haha, success!") "); }). Fail (function () {alert ("Error!) ");  
});     

5.animate ({step:function () {}})

Animation of one element while another element is animated

$ ("#go"). Click (function () { 
 $ (". Block:first"). Animate ({ 
  left:100 
 }, { 
  duration:1000, step 
  : function (now, FX) { 
   $ (". BLOCK:GT (0)"). CSS (' left ', Now ';}}}); 
 

6.clone ()

Use with the Appendto method to create a cloned element

<div class= "Container" > 
 <div class= "Hello" >Hello</div> 
 <div class= "Goodbye" > Goodbye</div> 
 
 

The result:

<div class= "Container" > 
 <div class= "Goodbye" > 
  goodbye <div class= 
  "Hello" >hello </div> 
 </div> 
</div> 
 
 

The result:

<div class= "Container" > 
 <div class= "Hello" >Hello</div> 
 <div class= "Goodbye" > 
  Goodbye 
  <div class= "Hello" >Hello</div> 
 </div> 
</div> 

The above is a small series for everyone to talk about jquery Advanced method description and application of all content, I hope that we support cloud-Habitat Community ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.