Search code examples
htmltwitter-bootstrapbootstrap-selectbootstrap-selectpicker

Cannot change title of Boostrap-select selectpicker


I want to programmatically change the title of my Bootstrap-select selectpicker.

I tried the following JS code which does not work.

$('#myPicker')
    .selectpicker({title: 'New title'})
    .selectpicker('render');

Any other ways I can do this?


Solution

  • Selectpicker will only update if the DOM has been updated. The function below should update title because it lets selectpicker append a new html object (DOM is changed)

    function newTitle() {
        var selectpicker = $("#myPicker");
        selectpicker.selectpicker();
        selectpicker.selectpicker({title: 'New Title'}).selectpicker('render');
        html = '';
        selectpicker.html(html);
        selectpicker.selectpicker("refresh");
    }