3

Pls what is the right way to pass options via javascript for bootstrap tooltip/popover: Via data attributes works as in:

<input type="text" data-toggle="tooltip" data-placement="right" data-animation="fade" data-delay="200" data-trigger="focus" data-content="foo">

But using javascript this doesn't:

<script>
    jQuery(function ($) {
        $("input").popover()({
            animation:"fade",
            delay: "200",
            trigger:"focus",
            placement: "right"
        });
    });
</script>

what is the right syntax?

2 Answers 2

5

For tooltip, it should be:

jQuery(function ($) {
    $("input").tooltip({...});
});

Instead of:

jQuery(function ($) {
    $("input").popover({...});
});

Update: Sorry for the mis-confusions, it works here but:

popover()({...});

Should be

popover({...});

HTML:

<input type="text" data-toggle="tooltip" data-placement="right" data-animation="fade" data-delay="200" data-trigger="focus" data-content="foo">

JS:

jQuery(function ($) {
    $("input").popover({
        animation:"fade",
        delay: "200",
        trigger:"focus",
        placement: "right"
    });
});

Make sure you have added the JavaScript and CSS files properly.

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

3 Comments

I want use a popover. Note: The $("input").popover() works when i pass options via data attributes as in the first example and so does$("input").tooltip(). Both don't work via javascript
That's because you're just initializing the popover with it's options (or like above without any options). To call the popover and cause it to display you need to use $('input').popover('show');
little errors in value definition: $("input").popover({ animation:true, delay: 200, trigger:"focus", placement: "right" });
3

Reveals an element's tooltip.

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

Hides an element's tooltip.

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

Toggles an element's tooltip.

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

Hides and destroys an element's tooltip.

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

Complete reference: Here

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.