Home > Article > Web Front-end > Analysis on the use of .add() in jquery_jquery
add() Adds an element to the collection of matching elements. This is the statement in the jquery reference manual. However, the example link provided is wrong, so there is no example description of add(). Here are a few examples to better understand the usage of add().
Example 1
Added this… (notice no border)
Explanation: add("p") here means the sum, that is, the css of $("div") and the css of p. Note here that the div has a border. And p does not.
Example 2
Hello
Hello Again
p and span css, equivalent to
$("p,span").css("background","yellow");
Example 3:
Hello
Clone() means to copy; copy a p and insert Again into the body of the document.
Insert a sentence here: If clone() is not used, the original p will no longer exist. Look at the following example:
Hello