JQuery-add element
With jQuery, you can easily add new elements/content.
Four jQuery methods for adding new HTML content:
- Append ()-insert content at the end of the selected Element
- Prepend ()-insert content at the beginning of the selected Element
- After ()-insert content after the selected Element
- Before ()-insert content before the selected Element
The jQuery append () method inserts content at the end of the selected element.
$("p").append("Some appended text.");
The jQuery prepend () method inserts content at the beginning of the selected element.
$("p").prepend("Some prepended text.");
The jQuery after () method inserts content after the selected element.
$("img").after("Some text after");
The jQuery before () method inserts content before the selected element.
$("img").before("Some text before");
What is the difference between the first two and the last two... I'm thinking about it... Code Analysis:
<Script src = "jquery-1.11.1.js"> </script> <script> $ (document ). ready (function () {$ ("# btn1 "). click (function () {$ ("# test1 "). prepend ("Before") ;}); $ (" # Btn2 "). click (function () {$ (" # test1 "). append ("After") ;}); $ (" # Btn3 "). click (function () {$ (" # test2 "). before ("Before") ;}); $ (" # Btn4 "). click (function () {$ (" # test2 "). after ("After") ;}); </Script>Add text in front of Fan tesiAdd text after fan terseyAdd text before fan tersiAdd text after still fan tersiVersace
Still ventsi
It feels troublesome to map images... Or text description... After clicking the four buttons, the effect is as follows:
BeforeVersaceAfter
BeforeStill ventsi
After
Did you find something... Continue, review elements:
Append () and prepend () methods, within the selected element (............
) Insert content;
After () and befZ finished? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> memory + ceiling/SBqUXVlcnmjrL/J0tS63Mjd0te12Mm + s/ceiling + ceiling/ycq508PS1M/ceiling + PGJyPgo8dWw + ceiling s/second + CjxwcmUgY2xhc3M9 "brush: java; "> $ (" # div1 "). remove ();
The jQuery empty () method deletes the child elements of the selected element.
$("#div1").empty();
Filter deleted elements
The jQuery remove () method can also accept a parameter that allows filtering of deleted elements.
This parameter can be the syntax of any jQuery selector.
The following example deletes allElement:
$("p").remove(".italic");
Here I thought about how to "delete all class =" italic"Element and delete
All class = "italic" elements "... That is:
$(".italic").remove("p");
Can the empty () method accept a parameter? The answer is no!
Another problem is that the following code is displayed:
Var txt2 = $ (""). Text (" Text. "); // create a new element with jQuery
Why can it be written in the above form? I am not quite clear about the rules... As you study in the future, you should know that day, haha... Put it here first ......