How to add <li> as the first element of a list in <ul>

I have an html page (index.html) that calls the ajax page (aj.php). Ajax page will return a certain amount <li>, for example

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

I already have list items in the <ul>html pages (index.html). When I try to add the result of the ajax page ie <li>, it is added last.

I want the one that <li>came back from the ajax page to be the first. How to achieve this. Please help. Any help would be appreciated

+3
source share
2 answers

, prepend, : -)

+8

.prependTo() jQuery? .

, - :

var returnedLIs = fromPHP;
$(returnedLIs).prependTo($('your ul'));
+2

Source: https://habr.com/ru/post/1764455/


All Articles