Bootstrap tooltip data-toggle

前端 未结 3 2508
伪装坚强ぢ
伪装坚强ぢ 2021-02-20 01:10

In the Bootstrap documentation page, the tooltip has a signature of:

hover over me
         


        
3条回答
  •  不要未来只要你来
    2021-02-20 01:40

    After reading some GitHub issue pages, I think I have come to the following conclusion (which is my best guess).

    Originally, in older versions of Bootstrap, the tooltip signature was:

    hover over me
    ...
    hover over me again!
    

    And developers could do:

    $(document).ready(function(){
        $('[rel="tooltip"]').tooltip();
    });
    

    To activate all tooltips at once (since each tooltip requires an initialization to work). In other words, it was just a convenient way to identify all the tooltips so that you can use jQuery to activate all of them.

    But rel="tooltip" did not validate against HTML5, so folks started suggesting using data-toggle="tooltip" because Bootstrap already uses data-toggle for other components and data-* is valid in HTML5.

    Thus, my guess is that there is no special semantic meaning or purpose for data-toggle="tooltip" other than to provide a convenient way to identity all tooltips.

    Note that you could also identify the tooltips using ID or class, but why not activate all tooltips at once (rhetorical question)?

提交回复
热议问题