Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force show bootstrap tooltip using javascript

I've been looking everywhere, is there any way to force show the tooltip, not using an event, but using a js code, because we all know the flaw of numerical input and the paste exploit.

<script type="text/javascript">
var previous;
//Buy Button JS code
$(function () {
    $("#searchform").bind('submit', function () {
        var str = $('#search-form').val();
        if (str.match(/^[0-9]*$/)) {
            //Great, continue executing the script.
        }
        else
        {
            //Force show a tooltip asking the user to numerically type the text.
        }
    });
});

like image 605
Omarrrio Avatar asked Mar 29 '16 19:03

Omarrrio


People also ask

How do I show tooltip in bootstrap?

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

How do I make tooltip always show?

Single element To make an element display its tooltip permanently, we use its showTooltipOn property. To make tooltip always be shown, set it to "always" .

How do I show tooltip without mouseover?

You want to show tooltip without mouseover? Then it's not called tooltip. Just use a usercontrol or even a textblock to do it. You position this control to where you want it and set visibility / or opacity to control how long you want to show it.

How do I show a tooltip on a disabled element?

By default, tooltips will not be displayed on disabled elements. However, you can enable this behavior by using the following steps: Add a disabled element like the button element into a div whose display style is set to inline-block . Set the pointer event as none for the disabled element (button) through CSS.


1 Answers

To trigger a tooltip to show up you need to use the 'show' option of the tooltip. Here is an example.

$('#element').tooltip('show')

Replace #element with your own selector.

To add title using Jquery itself you can do this

$('#element').tooltip({title:"test title"})

like image 160
Rajshekar Reddy Avatar answered Sep 21 '22 01:09

Rajshekar Reddy