lambypie
lambypie

Reputation: 481

msDropDown Delete all options

Please let me know how can I remove/clear all options from msDropDown. I have tried the below code and its not working fine.

    oHandler2 = $("#main").msDropDown().data("dd"); 
    oHandler2.remove();

Thanks in Advance. Lampy

Upvotes: 0

Views: 1391

Answers (3)

Tolga
Tolga

Reputation: 157

If you dont need to remove specify item, you can delete your element. And then create new one.

HTML

<div class="mainSection">
    <div id="main"></div>
</div>

Script

<script>
   $("#main").remove();
   $(".mainSection").append("<div id='main'></div>");
   $("#main").msDropDown().data("dd"); 
</script>

Upvotes: 0

Kumar_14
Kumar_14

Reputation: 584

In my opinion the best way to delete all item is

var oHandler = $("#main").msDropDown().data("dd");
oHandler.set("length", 0);

Upvotes: 1

dmullings
dmullings

Reputation: 7200

You need to specify an index when calling the .remove() method and you can get the count of all options by accessing the childElementCount property. Then you just need to remove all the options. Example below:

var oHandler2 = $("#main").msDropDown().data("dd");

for(var i = 0; i < oHandler2.childElementCount; i++){
    oHandler2.remove(0); //remove the current first option
}

Upvotes: 2

Related Questions