So fügen Sie ID in JQuery hinzu
$( "li" ).add( "<p id='new'>new paragraph</p>" )
.css( "background-color", "red" );
Dev
$( "li" ).add( "<p id='new'>new paragraph</p>" )
.css( "background-color", "red" );
$( "li" ).add( "p" ).css( "background-color", "red" );
$( ".container" ).append( $( "h2" ) );
$( "li" ).add( document.getElementsByTagName( "p" )[ 0 ] )
.css( "background-color", "red" );
<h2>Greetings</h2>
<div class="container">
<div class="inner">
Hello
<p>Test</p>
</div>
<div class="inner">
Goodbye
<p>Test</p>
</div>
</div>
var pdiv = $( "p" );
pdiv.add( "div" ); // WRONG, pdiv will not change
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
</ul>
<p>a paragraph</p>
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
<h2>Greetings</h2>
</div>