Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap Popovers not working

Here is my HTML:

<div id="disclaimer">After 30 Days you'll have the option to keep your account for $15 per month -no contract required-or revert to a single page free account.*</div>

JavaScript:

$('#disclaimer').popover({
  trigger: 'hover',
  html: true,
  placement: 'right',
  content: 'hello world'
});

When I hover over the element, nothing happens.. no JavaScript errors or anything, not sure whats wrong

like image 458
dennismonsewicz Avatar asked Jul 06 '13 03:07

dennismonsewicz


People also ask

Why are popovers not showing up?

js . Popovers are opt-in for performance reasons, so you must initialize them yourself. Zero-length title and content values will never show a popover. Specify container: 'body' to avoid rendering problems in more complex components (like our input groups, button groups, etc).

How do I enable popovers in bootstrap?

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 I show popover on hover?

To make the image on hover in popover just insert an image as an HTML element to the data-mdb-content and set the data-mdb-html to true .

Does bootstrap 5 require Popper?

Many of our components require the use of JavaScript to function. Specifically, they require our own JavaScript plugins and Popper.


2 Answers

Using your exact code, all I had to do to get it to work was wrap it in a function call and put the script below the div tag. If you placed your jQuery in an onload function it would work just as well. Good luck.

Use this:

<div id="disclaimer" >After 30 Days you'll have the option to keep your account for $15 per month -no contract required-or revert to a single page free account.*</div>

<script>
$(function ()  
{
  $('#disclaimer').popover(
  {
     trigger: 'hover',
     html: true,
     placement: 'right',
     content: 'hello world'
  });
});
</script>

OR

$(document).ready(function()
{
  $('#disclaimer').popover(
  {
     trigger: 'hover',
     html: true,
     placement: 'right',
     content: 'hello world'
  });
});
like image 147
Jonathan Avatar answered Sep 30 '22 17:09

Jonathan


i had been looking for over a day as to why my popover wasn't working after getting autodisabled due to events happening on my page (a complicated app, something that gets enabled/disabled depending on the state of what is going on) and the key was to NOT have it the document ready but to have it out in a function because it gets enabled after document initialization on a button click.

like image 34
lizz Avatar answered Sep 30 '22 18:09

lizz