2

I want to add dynamically generated list items to an unordered list in my jQuery mobile page.

But when I add new list items, the existing CSS isnt applied. sortedList is my ul.

Ive tried a few different things including:

jQuery('#sortedList').append('<li><h3>SUCCESS</h3></li>')

jQuery('#sortedList li').html('<h3>SUCCESS</h3>')

jQuery('#sortedList li').append('<h3>SUCCESS</h3>')

jQuery('#sortedList li').trigger('create');
jQuery('#sortedList li').append('<h3>SUCCESS</h3>')

Nothing works, any suggestions or advice would be greatly appreciated

Daft
  • 10,277
  • 15
  • 63
  • 105

1 Answers1

2

You should add all items to the list, then refresh the listview :

$('#sortedList').append('<li><h3>Success</h3></li>').listview('refresh');

Here's a JSFiddle.

As a sidenote: you don't have to spell out jQuery every time, to use jQuery. The $ symbol is another name for the jQuery object, so jQuery('#mySelector') is equivalent to $('#mySelector')

xdumaine
  • 10,096
  • 6
  • 62
  • 103
  • 1
    Cheers mate, this works perfectly! And Im aware of the $, but I have to use jQuery selector for this. Cheers though – Daft Sep 10 '13 at 11:24