1var $newdiv1 = $( "<div id='object1'></div>" ),
2 newdiv2 = document.createElement( "div" ),
3 existingdiv1 = document.getElementById( "foo" );
4
5$( "body" ).append( $newdiv1, [ newdiv2, existingdiv1 ] );
6
1$( "li" ).add( "<p id='new'>new paragraph</p>" )
2 .css( "background-color", "red" );
3
1$( "p" ).add( "div" ).addClass( "widget" );
2var pdiv = $( "p" ).add( "div" );
3
1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>id demo</title>
6 <style>
7 div {
8 width: 300px;
9 float: left;
10 padding: 2px;
11 margin: 3px;
12 background-color: #eee;
13 }
14 </style>
15 <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
16</head>
17<body>
18
19<div id="myID.entry[0]">id="myID.entry[0]"</div>
20<div id="myID.entry[1]">id="myID.entry[1]"</div>
21<div id="myID.entry[2]">id="myID.entry[2]"</div>
22
23<script>
24$( "#myID\\.entry\\[1\\]" ).css( "border", "3px solid red" );
25</script>
26
27</body>
28</html>
29
1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>add demo</title>
6 <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
7</head>
8<body>
9
10<p>Hello</p>
11<span>Hello Again</span>
12
13<script>
14$( "p" ).add( "span" ).css( "background", "yellow" );
15</script>
16
17</body>
18</html>
19
1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>add demo</title>
6 <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
7</head>
8<body>
9
10<p>Hello</p>
11<span id="a">Hello Again</span>
12
13<script>
14var collection = $( "p" );
15// Capture the new collection
16collection = collection.add( document.getElementById( "a" ) );
17collection.css( "background", "yellow" );
18</script>
19
20</body>
21</html>
22
1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>append demo</title>
6 <style>
7 p {
8 background: yellow;
9 }
10 </style>
11 <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
12</head>
13<body>
14
15<p>I would like to say: </p>
16
17<script>
18$( "p" ).append( document.createTextNode( "Hello" ) );
19</script>
20
21</body>
22</html>
23
1<h2>Greetings</h2>
2<div class="container">
3 <div class="inner">Hello</div>
4 <div class="inner">Goodbye</div>
5</div>
6