How to bind bootstrap tooltip on dynamic elements

前端 未结 2 1056
不思量自难忘°
不思量自难忘° 2020-12-29 03:34

When using Bootstrap tooltip, we need to write something like this to have tooltip functionality:

$(\".showtooltip\").tooltip();

But the pr

2条回答
  •  情深已故
    2020-12-29 04:02

    You need to use selector property. See on the documentation :

    "If a selector is provided, tooltip objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have tooltips added. See this and an informative example."

    JS example code :

    $('body').tooltip({
        selector: '.createdDiv'
    });
    
    $('#add-button').click(function() {
        $('
    Hover over me
    ').appendTo('#container'); });

    DEMO

提交回复
热议问题