The. Add of jquery is like a collection, and the official demo is an image of the meaning.
1<!doctype html>234<meta charset= "Utf-8" >5<title>add demo</title>6<script src= "//code.jquery.com/jquery-1.10.2.js" ></script>78<body>9<p>Hello</p>Ten<span id= "a" >hello again</span> One<script> A varCollection = $ ("p" ); - //Capture the new collection -Collection = Collection.add (document.getElementById ("a" ) ); theCOLLECTION.CSS ("Background", "yellow" ); -</script> -</body> -Although like collection, note the following differences:
var pdiv = $ ("P");pd Iv.add ("div") pdiv.css ("Background-color", "green" ), the above code, Only the P background color turns green, and the background color of the div does not change. Instead, the background color of the div will turn green. var pdiv = $ ("p"= Pdiv.add ("div") pdiv.css ("Background-color", "green");
This "broken chain" problem is also shown in the following demo (examples in the jquery website)
1<!doctype html>2 34 56 7<meta charset= "Utf-8" >8 9<title>add demo</title>Ten One<style> A - Div { - the width:60px; - - height:60px; - + margin:10px; - + float: Left; A at } - - p { - - Clear:left; - infont-Weight:bold; - tofont-size:16px; + - Color:blue; the *margin:010px; $ Panax Notoginseng padding:2px; - the } + A</style> the +<script src= "//code.jquery.com/jquery-1.10.2.js" ></script> - $ $ -<body> - the - Wuyi<div></div> the -<div></div> Wu -<div></div> About $<div></div> - -<div></div> - A<div></div> + the - $<p>added This... (Notice no border) </p> the the the the<script> - in$ ("div"). CSS ("Border", "2px solid Red" ) the the. Add ("P" ) About the. CSS ("Background", "yellow" ); the the</script> + - the Bayi</body> the theAPI-. Add ()