Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove elements from listview JQUERY mobile

There is a list view and this is loaded dynamically upon loading the page. This adds elements inside list view. The problem is i have placed backbutton.After going to previous screen and returning back to current screen it is loading the data and appending to the List View.

I need to remove the <li> elements from the list view.

The HTML code snippet.
<ul id="mymenu" data-role="listview" >
</ul>

Jquery Code Snippet.
$("#mypmenu").append('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>'); 


Now i need to remove the elements from the list view (mymenu)which are loaded already.
like image 450
shyamshyre Avatar asked Jan 04 '12 12:01

shyamshyre


1 Answers

Try emptying your list before appending list items first. Afterwards, make sure to call the refresh function of the listview widget, so jQuery Mobile will be rendering your list correctly.

$("#mypmenu").empty().append('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>').listview("refresh"); 

See also http://forum.jquery.com/topic/dynamically-generated-listview

like image 153
Christoph Baudson Avatar answered Sep 30 '22 01:09

Christoph Baudson