How to Create an HTML Bootstrap Tooltip for each option in Select tag?

Anatol

I have read many questions but didn't find any, which actually show an answer to my question.

How to can I create an HTML Bootstrap tooltip for each option in a select tag?

You can use the following dropdown for the purpose of this:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

<select>
    <option title="<h1>Tooltip 1</h1>">Hover over me</option>
    <option title="<h1>Tooltip 2</h1>">Hover over me</option>
    <option title="<h1>Tooltip 3</h1>">Hover over me</option>
    <option title="<h1>Tooltip 4</h1>">Hover over me<h1></option>
</select>

<script>
    $(document).ready(function(){
        $('option').tooltip({html:true});
    });
</script>
Anatol

I haven't found any way to show an HTML tooltip on an option tag. However, I found a more creative way to achieve exactly the same by using a Bootstrap dropdown.

$(document).ready(function() {
  // change dropdown button text when a dropdown option is clicked
  $('.dropdown-item').click(function() {
    $('.dropdown-toggle').text($(this).text());
  });

  // show html tooltip
  $('[data-toggle="tooltip"]').tooltip({
    html: true,
    placement: "right"
  });
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

<div class="container">
  <div class="dropdown">
    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">First Option</button>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#" data-toggle="tooltip" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">First Option</a>
      <a class="dropdown-item" href="#" data-toggle="tooltip" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">Second Option</a>
      <a class="dropdown-item" href="#" data-toggle="tooltip" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">Third Option</a>
    </div>
  </div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to add tooltip on each select option with bootstrap-select

How to add a tooltip to a <option> in a <select> box in HTML?

How to apply tooltip to option tag which already exists for the parent select tag in JSP?

how to create an html tooltip

HTML <select> and <option> conditional tag

How to set two different values in the select option HTML tag?

How to apply font family in HTML tag of select option

How to open option list of HTML select tag on onfocus()

How to set Option of Select HTML tag using data- attribute

how to clean option values under select - html tag

how create if for option in select?

Excel VBA change option in the HTML select tag

vbscript capture text in the html select option tag

Is it possible to add a form as an option in a HTML select tag?

Bootstrap's tooltip part of HTML tag is not interpreted by GWT Project

Create an image with a tooltip tag

How to create a tag field with Bootstrap?

Set background color on select HTML tag based on the background of an OPTION tag

How to create option inside select tag dynamically with ajax response text in php?

How to create new Bootstrap select picker controls on HTML loaded by AJAX?

How to add JSON data in select and option tag?

How to append option tag to select in jqyery

each option in select tag disable a specific element in page

Getting a Select tag created for each option, instead of one for all options

how to choose selected option in select/option in HTML?

Having django select the right option for a html select tag

Auto select pre and next option for html select tag

HTML: select default option when select tag holds a function

What if value for select option is not specified in html select tag