appendTo add dom as last element in target but how to add it as first?
I want to add element to as first as below. How can i do this ?
$('<li>').appendTo($('ul')); // add it as last element
<ul>
<!-- i want to add element here -->
<li></li>
<li></li&开发者_Python百科gt;
</ul>
Use jQuery's .prepend() http://api.jquery.com/prepend/
$('ul').prepend('<li>new</li>')
Your looking for the prependTo
method.
精彩评论