7

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.
        }
    });
});

3 Answers 3

12

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"})

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, you answered both questions :)
3

To show tooltip

$('#youtooltip').tooltip('show');

Your code:

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
        {
            $('#youtooltipid').tooltip('show');
            // or $('.youtooltipclass').tooltip('show');
        }
    });
})

Comments

1

try

$('[data-toggle="tooltip"]').tooltip()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.