1TO add dynamically:
2let $id=0;
3$('ul li').each(()=>{
4///use this also $('ul').children("li").each(function()=>{/// same below code})
5 ///this will select the element under current selection,
6 ///THis outside the function relates or selects body, inside the function
7 /// denotes the selector php and js in think all library may be syntax
8 ///get vary
9 $(this).attr('id','id'+$id)
10 $i=$i+1
11})
12using js
13///place the script just above to </body>
14const s=document.getElementsByTagName('li');
15len=s.length;
16console.log(len)
17for(let i=0;i<len;i++){
18 s[i].id="id"+i;
19}
20
21
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<strong>Hello world!!!</strong>
16<p>I would like to say: </p>
17
18<script>
19$( "p" ).append( $( "strong" ) );
20</script>
21
22</body>
23</html>
24
1$( "li" ).add( document.getElementsByTagName( "p" )[ 0 ] )
2 .css( "background-color", "red" );
3