ouhma ouhma - 1 year ago 67
Javascript Question

How to clean completly select2 control?

I'm working with the awesome select2 control.

I'm trying to clean and disable the select2 with the content too so I do this:


Ok, it works, but if i had a value selected all the items are removed, the control is disabled, but the selected value is still displayed. I want to clear all content so the placeholder would be showed. Here is a example I did where you can see the issue: http://jsfiddle.net/BSEXM/


<select id="sel" data-placeholder="This is my placeholder">
<option value="a">hello</option>
<option value="b">all</option>
<option value="c">stack</option>
<option value="c">overflow</option>
<button id="pres">Disable and clear</button>
<button id="ena">Enable</button>


$(document).ready(function () {

$("#pres").click(function () {

$("#ena").click(function () {


#sel {
margin: 20px;

Do you have any idea or advice to this?

Answer Source

Why all this trouble???


 $('#sel').select2('data', null);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download