最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to append a <li> as the first list item in a <ul> - Stack Overflow

programmeradmin2浏览0评论

I have a html page (index.html) which calls the ajax page(aj.php). The Ajax page will return some number of <li>'s, like

<li>Blue Flower</li>
<li>White Assassin</li>

I already have some list items in the <ul> of the html page(index.html). When i try to append the result of the ajax page i.e.,<li>'s, it is appending at the last.

I want the <li>'s which returned from ajax page should be at first. How to achieve this?

I have a html page (index.html) which calls the ajax page(aj.php). The Ajax page will return some number of <li>'s, like

<li>Blue Flower</li>
<li>White Assassin</li>

I already have some list items in the <ul> of the html page(index.html). When i try to append the result of the ajax page i.e.,<li>'s, it is appending at the last.

I want the <li>'s which returned from ajax page should be at first. How to achieve this?

Share Improve this question edited Mar 20, 2022 at 10:09 halfer 20.3k19 gold badges109 silver badges202 bronze badges asked Sep 13, 2010 at 8:52 RajasekarRajasekar 19k35 gold badges109 silver badges140 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

If you want to have the items at first, its prepend, not append :-)

Are you looking for the .prependTo() function of jQuery? Docs are here.

So it'd be something like:

var returnedLIs = fromPHP;
$(returnedLIs).prependTo($('your ul'));
发布评论

评论列表(0)

  1. 暂无评论