N
N
naneri2014-07-02 09:58:48
JavaScript
naneri, 2014-07-02 09:58:48

How not to prescribe functionality for each individual tooltip in Bootstrap?

Now I am supporting a site that uses bootstrap. I use the native bootstrap component - the tooltip, but the code turns out to be too bloated - apparently I misunderstood something somewhere.
Currently, to add tooltips, I add an event trigger in javascript for each tooltip, despite the fact that the code is the same everywhere, only the selectors are different. Is there a way to avoid this?
Example code (this is for the first tooltip, for the next one it's the same only with a different selector):

$(document).ready(function(){
                    $('#tool').hover(
                            function(){
                        $('#tool').tooltip('show');
                    },function(){
                        $('#tool').tooltip('hide');
                    });
    })

I add the tooltip as it says in the Bootstrap2 documentation

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Popov, 2014-07-02
@naneri

$(document).ready(function(){
$(".tooltip").tooltip() //tooltip общий класс для всех элементов у которых будет tooltip
})

The second option (from the same documentation where elements are "recognized" as "elements with a tooltip" by data-toggle="tooltip"):
<a href="#" data-toggle="tooltip" title="first tooltip">hover over me</a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question