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>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
12<script>
13$( "p" ).clone().add( "<span>Again</span>" ).appendTo( document.body );
14</script>
15
16</body>
17</html>
18