Twitter Bootstrap popover not working on first click

I show a popover when I click on the anchor. But popover does not start on the first click, no matter how it works on the second click.

HTML:

    <!-- Pop Check -->
<div class="popover-markup">
   <input class="checkbox-inline" type="checkbox" value="Option1">
   <a href="javascript:void(0)" class="trigger" data-placement="bottom" tooltip="Manage Users">Option1</a>
   <!-- Popup Content-->
   <div class="content hide">
      <div class="head hide">Select Users For Option1<span class="close_popover"><i class="fa fa-times"></i></span></div>
      <div>
         <label class="checkbox-inline">
         <input type="checkbox" id="" class="si_DSCM" value="user6"> User 6
         </label>
      </div>
   </div>
</div>

JS:

$(document).on('click', ".popover-markup>.trigger", function () { 

    $(this).popover({
        html: true,
        title: function () {
            return $(this).parent().find('.head').html();
        },
        content: function () {
            return $(this).parent().find('.content').html();
        }
    });    
});

This is my fiddle: https://jsfiddle.net/47pef6g8/

I found similar questions, but that did not help me in my case.

Please, help. Thanks in advance.

+4
source share
1 answer

By looking at your code, it is very clear that you are initializing a popover on click. Therefore, to display a popover, two clicks are required. My suggestion to you would be to initialize a popover when loading a document.

Fiddle .

$('[data-toggle="popover"]').popover({
    html: true,
    title: function () {
        return $(this).parent().find('.head').html();
    },
    content: function () {
        return $(this).parent().find('.content').html();
    }
}); 

, .

-:

+3

Source: https://habr.com/ru/post/1625265/


All Articles