Ris
Ris

Reputation: 1164

Reset bootstrap drop down list

I am trying to reset bootstrap drop down with placeholder but it's not working.Here is my declaration,

<div class="form-group" id="div_emp_type_involved">
    <label for="sri_EmpTypeInvolved" class="col-md-4 control-label">Type</label>
        <div class="col-md-7">
            <select data-placeholder="Select type" id="sri_EmpTypeInvolved" name="sri_EmpTypeInvolved" class="chosen-select">
            Option 1
            Option 2
            </select>
        </div>
</div>

On button click I am trying,

$("#sri_EmpTypeInvolved").addclass("placeholder","select type");

But it's not working. What would be correct way to achieve the same ?

Upvotes: 0

Views: 1478

Answers (1)

Matt O&#39;Connell
Matt O&#39;Connell

Reputation: 287

If you're trying to set a placeholder for your dropdown list, here's how you'd do it:

<div class="form-group" id="div_emp_type_involved">
    <label for="sri_EmpTypeInvolved" class="col-md-4 control-label">Type</label>
    <div class="col-md-7">
        <select data-placeholder="Select type" id="sri_EmpTypeInvolved" name="sri_EmpTypeInvolved" class="chosen-select">
            <option disabled selected>Select Type</option>
            <option>1</option>
            <option>2</option>
         </select>
    </div>
 </div>

If you need to change it on a button click:

$('button').click(function(){
    $('#div_emp_type_involved option').eq(0).text('some new placeholder text');
})

Upvotes: 1

Related Questions