King Kong
King Kong

Reputation: 2915

jquery selectmenu not initializing

I am using filamentgroup jquery selectmenu(), I am calling it on the dynamically built selectlist and on the selectlist which is already built but options are addying dynamically like:

First case

        $("presentselectlist").selectmenu();      //present selectlist initialized

        $("presentselectlist").html("<option></option>.."); // addding options dynamically 

        $("presentselectlist").selectmenu();  // then reinitilaized, but not working this line

second case

        var newselectlist = $("<select ..."); // creating new selectlist dynamicallly

        $(newselectlist).selectmenu();      // then initialized it by selectmenu but not working

Upvotes: 1

Views: 1287

Answers (1)

TJ VanToll
TJ VanToll

Reputation: 12704

In order to alter the options in a selectmenu you'll need to disable it, alter the <select> to your liking, destroy it, then recreate it.

$('select')
    .selectmenu()
    .selectmenu('disable')
    .append($('<option></option>').attr('value', 'Tiger').text('Tiger'))
    .selectmenu('destroy')
    .selectmenu();

Live Example - http://jsfiddle.net/kpMkw/1/

This is not ideal but it will work.

Upvotes: 2

Related Questions