Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 popover and tooltip on the same element

it is possible to use a tooltip and popover of Bootstrap 3 on the same element?

I have a table and want to show on each row (tr) a tooltip. Additionally I want to show a popover when a user clicks on the row. Both components need the data-toggle attribute so I doubt it is possible to do so.

Does anybody knows if it is possible or if there is a workaround?

like image 553
Lotus Avatar asked Jun 08 '14 14:06

Lotus


People also ask

What is the difference between popover and tooltip?

Tooltip: use tooltips to show a short text to respondents when they hover over a word or icon. Popover: use popovers to show a longer text, or when you want to have a link to an external web page. It is shown when the respondent clicks on a word or icon.

How do I show popover on hover?

Set the trigger option of the popover to hover instead of click , which is the default one. Or with an initialization option: $("#popover"). popover({ trigger: "hover" });

How do I use bootstrap popovers?

How To Create a Popover. To create a popover, add the data-toggle="popover" attribute to an element. Note: Popovers must be initialized with jQuery: select the specified element and call the popover() method.

How do you hide a popover?

To show or hide the Popover programmatically, call the show() or hide() method. The same thing can be done using the toggle(showing) method.


2 Answers

You dont have to use data-toggle, title and so on. Invoke the bootstrap plugins manually. See this example :

<table>
  <tr tooltip-title="Tooltip title #1" 
      popover-title="popover title #1" 
      popover-content="popover content #1">
    <td>qwerty</td><td>qwerty</td><td>qwerty</td><td>qwerty</td>  
  </tr>
  <tr tooltip-title="Tooltip title #2" 
      popover-title="popover title #2" 
      popover-content="popover content #2">
    <td>qwerty</td><td>qwerty</td><td>qwerty</td><td>qwerty</td>               
  </tr>
</table> 

script :

$('tr').each(function() {
  $(this).popover({    
    content : $(this).attr("popover-content"),
    title : $(this).attr("popover-title")         
  })     
  $(this).tooltip({    
    placement : 'bottom',  
    title : $(this).attr("tooltip-title")         
  })     
})

demo fiddle -> http://jsfiddle.net/79fXt/

like image 101
davidkonrad Avatar answered Oct 12 '22 00:10

davidkonrad


I needed both tooltip and popover on the same element. The tooltip is for information when the user hovers, and the popover is for a confirmation box when they click.

In this case, I need the tooltip to go away when the popover appears. I added a little bit of code to @davidkonrad's solution like this:

  $(this).popover({    
    content : $(this).attr("popover-content"),
    title : $(this).attr("popover-title")         
  }).tooltip({    
    placement : 'bottom',  
    title : $(this).attr("tooltip-title")         
  }).on('show.bs.popover', function() {
    $(this).tooltip('hide')
  })
like image 24
FirstVertex Avatar answered Oct 11 '22 23:10

FirstVertex