API-. Add ()

Source: Internet
Author: User

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  the

API-. Add ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.