prepend、prependTo

1.prepend


prepend、prependTo

 

$(document).ready(function(){
			$('.container').prepend($('h2'));
		});


prepend、prependTo

 

2.prependTo

 

 

Consider the following HTML:

 

<h2>Greetings</h2>
<div class="container">
  <div class="inner">Hello</div>
  <div class="inner">Goodbye</div>
</div>

 We can create content and insert it into several elements at once:

 

$('<p>Test</p>').prependTo('.inner');
<h2>Greetings</h2>
<div class="container">
  <div class="inner">
    <p>Test</p>
    Hello
  </div>
  <div class="inner">
    <p>Test</p>
    Goodbye
  </div>
</div>
 

你可能感兴趣的:(html)