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:
Test content 1
Test content 2
jQuery code:
The result obtained is:
Test content 1
New Add content
Test content 2
Add content
I don’t quite understand here. Why only the first
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 ;
2.$('
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;
3.$('
New content
').appendTo('div').addClass('c1' ).end() returns [p.c1], which is the
in the first
. In the 2nd operation, the last "destroyed" is the < in the second
;p>, so the object of his previous operation was the
in the first
, and that is what is returned;
4.$('
New content p>').appendTo('div').addClass('c1').end().addClass('c2') still returns the
;
in the first
Now I understand a little bit, the key is to find out what is the previous element of the last operated element.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31