Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax: Appending list-item at the top

Tags:

jquery

ajax

I'm calling a php processing file using ajax an appending the returned HTML usign the code below

$.ajax({
    type: "POST",
    url: "proc/process.php",
    data: dataString,
    cache: false,
    success: function(html){
        $("ul#lists").append(html);
        $("ul#lists li:last").fadeIn("slow");
        $("#flash").hide();
    }   
});

It appends a <li></li> item at the end of the ul#lists. I want the returned list-item <li></li> at the top of the lists instead of being appended at the last. How do I do that??

like image 488
ptamzz Avatar asked Oct 28 '25 16:10

ptamzz


1 Answers

You may try the .prepend() function:

$("ul#lists").prepend(html);
$("ul#lists li:first").fadeIn("slow");

And here's a live demo.

like image 130
Darin Dimitrov Avatar answered Oct 30 '25 13:10

Darin Dimitrov