1

I was wondering about how to empty a list in a proper way. Is it better to have a list in a div and then empty the div or the list?

I know this is a lame question but please help my understand this empty() function:)

Case) What happens if I run this script:

$('#mylist).empty();

...on this list:

<ul data-role="listview" id="mylist" data-inset="true" data-theme="a"><li>Hello!</li></ul>

Does it become: A):

<ul data-role="listview" id="mylist" data-inset="true" data-theme="a"><li></li></ul>

Or does it become: B):

<ul data-role="listview" id="mylist" data-inset="true" data-theme="a"></ul>

Or does it become just this: C):

<ul></ul>

It looks like it becomes just this because next time I try to add stuff to my "mylist" list after I have run empty() on it. I want it to still have the listview format and not this:

 <ul></ul>. 

MyCode snippet:

$('#mylist').empty();
var newlist = "<ul data-role=" + "'listview'" +" id=" + "'mylist'" + " data-inset=" + "'true'" + " data-theme=" + "'a'" + "><li>Hello!</li></ul>";
$('#mylist').append(newlist).listview().trigger('create');
0

1 Answer 1

5

It becomes B). But as I understand, you problem is that listview styles are not applied to newly added list item. Take a look at this According to it, you should do:

$('#mylist').empty();
var newlist = "<ul data-role=" + "'listview'" +" id=" + "'mylist'" + " data-inset=" + "'true'" + " data-theme=" + "'a'" + "><li>Hello!</li></ul>";
$('#mylist').append(newlist).listview("refresh").trigger('create');

See .listview(). changed to .listview("refresh")..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.