开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜