Home >Web Front-end >JS Tutorial >About the use of end() in jQuery_jquery
The end() method is described in the official API like this: "Go back to before the most recent "destructive" operation. That is, change the matching element list to the previous state.";
It seems like Find the previous element of the last operated element, in the following example:
html code:
New content
New Add content
Add content
tag has two styles? What is returned after the end() method? I added monitoring in Firefox and got the following results:
1.$('
New content
').appendTo('div') returns: [p,p] object array, that is, the two added p tags ;New content
').appendTo('div').addClass('c1') returns: [p.c1,p.c1] Object array, that is, the p object array after adding the c1 class style;New content
').appendTo('div').addClass('c1' ).end() returns [p.c1], which is thein the first
in the first
New content p>').appendTo('div').addClass('c1').end().addClass('c2') still returns the
;
in the first