End of the Whole Shi Man ();

Source: Internet
Author: User

This evening to the small partners to Exchange learning Jquerydom operation, encountered the end () method, and then tangled together for a long time, the jquery document is very general, must be thin taste to know a probably

theintheandreturnthesetoftoits previous state.结束当前链中最近的过滤操(有的成为破坏性)作并返回匹配的元素集合到其之前的状态。

Then jQuery1.7 's document gives an example

<div></div><div></div>
 $("<p/>")   .appendTo("div")   .addClass("test")   .end()   .addClass("test2");

The result after the run is

<div><p class="test test2"></p></div><div><p class="test"></p></div>

Have not confused why the first Div will add two class, and the second one ... A few small partners on the subject discussed together to discuss (both use end);
A variety of information, a meeting, all are blindfolded, and then use Firefox debugging, step-by-step operation, have a look

1.$(' <p/> '). AppendTo (' div ') returns an array of [p,p] objects, that is, the new two P tags;2.$(' <p/> '). AppendTo (' div '). AddClass (' C1 ') returns an array of [P.C1,P.C1] objects, that is, an array of P objects after the C1 class style has been added;3.$(' <p/> '). AppendTo (' div '). AddClass (' C1 ').End() returned is [P.C1], which is the first1a <div> <p>2Operation, the last "destruction" is the first2The <p&gt of a <div>, so his previous operation was the first object of the1A <p&gt in <div>, and the return is it;4.$(' <p/> '). AppendTo (' div '). AddClass (' C1 ').End(). addclass (' C2 ') returned is still the first1<p>; in a <div>

The end () method can go back to the most recent "destructive" operation, and the list of elements that will be matched changes to the previous state.
If no destructive action is returned an empty set.
Disruptive operation concept: refers to any action that alters the matched element. You may be vague about this concept, for example:

$("li").css("color","red");

The CSS function of the above code is not a destructive operation, because the list of matching elements does not change, it is the CSS property that changes the content of the text in the element.

$("li").find(".first")

The above code is a destructive operation, because the list of matching elements has changed, such as having three Li elements, then the list of matching elements has three elements, but after filtering using the Find () method, the list of matching elements has only one element, which is the "destructive" operation.
Look at one more example.

<%@ page language="java" contenttype="text/html; Charset=utf-8 "pageencoding="utf-8"%><! DOCTYPE html><html><head><meta http-equiv="Content-type" Content="text/html; Charset=utf-8 " /><title>Home of the script</title><script type="text/javascript" src="... /js/jquery-1.7.2.min.js "> </script><script type="Text/javascript"> $ (document). Ready (function   ()  { $ (). Find (). CSS ( "color" ,  "green" ); $ (). Find (). End (). CSS ( "color" ,  "blue" ); //$ (". Third"). Find (". js")  //$ (". Third"). CSS ("Color", "Red")  $ ( ". Third" ) . Find (). CSS ( "color" ,  "blue" ). End (). CSS ( "color" ,  "red" )}) </script></head><body><div> <ul class="First">  <li>HTML area</li>  <li>JavaScript zone</li>  <li class="div">Div+css Zone</li>  <li>jquery Zone</li> </ul> <ul class="Second">  <li>HTML area</li>  <li>JavaScript zone</li>  <li class="div">Div+css Zone</li>  <li>jquery Zone</li> </ul> <ul class="Third">  <li>HTML area</li>  <li class="js">JavaScript zone</li>  <li>Div+css Zone</li>  <li>jquery Zone</li> </ul></div></body></html>

The part that is commented on is equivalent to the most right sentence, this end needs to slowly experience!
Tonight, go to sleep with a "destructive" ...

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

End of the Whole Shi Man ();

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.