Page 1 of 1

how to remove all jquery listelements

Posted: Tue Dec 27, 2011 7:27 pm
by yacahuma
Hello,

I am playing with jquerymobile and want to populate a list with ajax. It works, but it keeps adding list to the ul. I need a way to remove all elements before adding the new ones.

here is my code

Code: Select all

            
             function getData(filter) {

                var output = $('#search_results');

                $.ajax({
                    url: 'requestSearchVisitor.php?carplate='+ filter,
                    dataType: 'json',
                    timeout: 5000,
                    complete: function() {
                        $("#search_results").listview("refresh");
                    },

                    success: function(data, status){
                        $.each(data, function(i,item){
                            var place = '<li><a href="">'+item.value+'</li>';
                            output.append(place);
                        });
                    },
                    error: function(){
                        output.text('There was an error loading the data.');
                    }
                });

            }


            $(document).ready(function() {
                $("#carplate").keyup(function(e)   {
                    e.preventDefault(); 
                    var search_input = $(this).val();
                    getData(search_input);
                     return false;
                });


            });