Gulaev Valentin Gulaev Valentin - 2 years ago 138
Javascript Question

How create dynamically selectmenu in jQuery Mobile?

I am trying to dynamically create a

element, but it isn't styled by jQuery Mobile. What is the correct way to achieve this?


Answer Source

Here's a working jsFiddle example:

$(document).on('pagebeforeshow', '#index', function(){    
    // Add a new select element    
    $('<option>').attr({'value':'1'}).html('Value 1').appendTo('#select-choice-1');
    $('<option>').attr({'value':'2'}).html('Value 2').appendTo('#select-choice-1');    
    // Enhance new select element

Also take a look at this ARTICLE, there you will find different method of enhancing jQuery elements markup, or it can be found HERE.

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