简体   繁体   中英

How do I make a tooltip of the option already selected from a select

I have a select which has a tooltip applied for each option. I would like to know how to make the tooltip work for the option that is already selected.

 $(document).tooltip();
 <select> <option value="one" title="Option one">one</option> <option value="two" title="Option two">two</option> <option value="three" title="Option three">three</option> </select>

According to documentation ,

$(document).tooltip();

Working sample: https://jsbin.com/pogudavuxu/edit?html,js,output

Answer: Update select title on change,

 $(document).ready(function(){ $("#sel").change(function() { this.title = $(this).val(); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <select title="one" id="sel"> <option value="one" title="Option one">one</option> <option value="two" title="Option two">two</option> <option value="three" title="Option three">three</option> </select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM