How jquery removes the first element
This article mainly introduces "how jquery removes the first element". In daily operation, I believe many people have doubts about how jquery removes the first element. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how jquery removes the first element"! Next, please follow the editor to study!
Methods to remove the first element: 1, the use of "eq (0)" selector and remove () method, syntax "$(" element "). Eq (0). Remove ()"; 2, the use of ": first" selector and remove () method, syntax "$(" element: first "). Remove ()".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Jquery removes the first element
Method 1: "eq (0)" selector + remove () method
Get the first element object using the "eq (0)" selector
Delete the selected element using the remove () method
$(document) .ready (function () {$("# but1") .click (function () {$("p"). Eq (0). Remove ();})
The first paragraph
The second paragraph
The third paragraph
The fourth paragraph
The fifth paragraph
The sixth paragraph
Delete the first element
Method 2: ": first" selector and remove () method
Get the first element object using the ": firs" selector
Delete the selected element using the remove () method
$(document) .ready (function () {$("# but1") .click (function () {$("p:first"). Remove ();})
The first paragraph
The second paragraph
The third paragraph
The fourth paragraph
The fifth paragraph
The sixth paragraph
Delete the first element
At this point, the study on "how to remove the first element of jquery" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!