How to remove items from the JQUERY mobile list

There is a list, and it loads dynamically when the page loads. This adds list items. The problem is that I placed the backbutton. After going back to the previous screen and returning to the current screen, it loads the data and adds it 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. 
+6
source share
4 answers

Try to clear your list before adding list items. After that, be sure to call the listview widget update function, so jQuery Mobile will display 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

+6
source

$("mypmenu").empty(), followed by $("mypmenu").append()

doing work for me

0
source

this work is for me

 $("mypmenu li").remove(); 
0
source

Do not use append then. Using

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

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


All Articles