shyamshyre shyamshyre - 1 year ago 92
jQuery Question

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" >

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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download