Someone else asked this question here, but there was no answer or solution given.
These bootstrap files are listed at the top of my application.js file:
...
//= require bootstrap-tooltip
//= require bootstrap-popover
...
My bootstrap_additions.js.coffee file contains:
$("a[rel=popover]").popover()
$(".tooltip").tooltip()
$("a[rel=tooltip]").tooltip()
In a view I have:
<a href="#" class="btn" rel="popover" title="Title" data-content="Some content.">click</a>
When i enter localhost:3000/assets/application.js in the browser, the bootstrap-popover.js content is present. In addition i found the following:
jQuery(function() {
$("a[rel=popover]").popover().on('click', preventDefault());
$(".tooltip").tooltip();
return $("a[rel=tooltip]").tooltip();
});
When the link is clicked the browser display is moved to the top of the page. When I scroll back down to the link, the popover is displayed. All is working except preventDefault. What am I missing?
Thanks.
UPDATE: To keep things clean in my code, i found the coffeescript version of the selected answer:
$("a[rel=popover]").popover().click (e) => e.preventDefault()
When I use the native Bootstrap PopOver with HTML in it's content, the frontend is not displaying that PopOver and the HTML Source is malformatted. Make sure to add the JS to the Toolset > Layouts JS/CSS section and to use jQuery instead of $. This support ticket is created 5 years, 3 months ago.
How To Create a Popover. To create a popover, add the data-toggle="popover" attribute to an element. Use the title attribute to specify the header text of the popover, and use the data-content attribute to specify the text that should be displayed inside the popover's body: Note: Popovers must be initialized with jQuery: select ...
The Popover plugin is similar to tooltips; it is a pop-up box that appears when the user clicks on an element. The difference is that the popover can contain much more content. Click To Toggle Popover Click To Toggle Popover
However, you can use the data-bs-trigger="focus" attribute which will close the popover when clicking outside the element: Tip: If you want the popover to be displayed when you move the mouse pointer over the element, use the data-bs-trigger attribute with a value of " hover ":
Using Twitter Bootstrap Popover
Updated to be in Coffeescript
1st approach
Instantiate
$("a[rel=popover]").popover()
Handle
$("a[rel=popover]").click (event) ->
event.preventDefault()
event.stopPropagation()
$(this).popover "show"
2nd approach
Taken directly from their source code:
$("a[rel=popover]").popover().click (e) ->
e.preventDefault()
You can also chain as this :
$("a[rel=popover]")
.on('click',function(e){
e.preventDefault();
})
.popover();
You can use a 'span' tag instead of an 'a' tag so that you don't need to preventDefault.
also prevent default should be associated with an event.
http://api.jquery.com/event.preventDefault/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With