开发者

appendTo add dom as last element in target but how to add it as first?

开发者 https://www.devze.com 2023-02-27 09:39 出处:网络
I want to add element to as first as below. How can i do this ? $(\'<li>\').appendTo($(\'ul\')); // add it as last element

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

精彩评论

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

关注公众号