Search code examples
jqueryhtmlcsstwitter-bootstrapbootstrap-selectpicker

How to add title (tooltip) on selectpicker disabled option?


I have a selectpicker with many languages i.e. <li> tags under <ul> tag as below given image.

Drop Down List (selectpicker)

It can be seen that the + Add Language li of selectpicker is disabled. It is happening because in actual html's <select>'s option is disabled as following image

HTML view

Now the concern is: selectpicker picks the select option and apply all the properties but did not carry the title (it can bee seen on <select>'s <option> value; title="My Title") while hover over the disabled <li> tag. In my opinion it is happening because disabled class on this <li> tag is overriding the title behavior by adding that ban icon.

Please let me know how can I enable this behavior while using select picker. I want title to be displayed while hovering over the disabled option.

Edit: Kindly refer to the code snippet for better understanding.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css" rel="stylesheet"/>
Language:
<select class="selectpicker">  
    <option>English</option>
    <option disabled title="My Title">+ Add Language</option>    
</select>


Solution

  • You can use the attribute data-content

    From the docs:

    <select class="selectpicker">
      <option data-content="<span class='label label-success'>Relish</span>">Relish</option>
    </select>
    

    With this attribute you can pass the output "template" there you can set a title attribute.

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css" rel="stylesheet"/>
    
    Language:
    <select class="selectpicker">  
        <option data-content="<span title='English'>English</span>">English</option>
        <option disabled title="My Title" data-content="<span title='+ Add Language'>+ Add Language</span>">+ Add Language</option>    
    </select>