Search code examples
javascriptjqueryhtmltwitter-bootstrapbootstrap-popover

Bootstrap popover on click event not showing


My popover isn't working when I trigger an evenLimitClick event in my fullcalendar. It works fine in my dayClick event, but nothing happens in my eventLimitClick. Here is my fiddle I even tried setting the popover to be called on the parent (ex. $(this).parent().popover, but that didn't work either.

$(document).ready(function () {

    // page is now ready, initialize the calendar...
    var eventsArray = [{
        title: 'Test1',
        start: new Date()
    }, {
        title: 'Test2',
        start: new Date("2015-04-21")
    }, {
        title: 'Test3',
        start: new Date("2015-04-21")
    }];

    $('#calendar').fullCalendar({
        // put your options and callbacks here
        header: {
            left: 'prev,next', //today',
            center: 'title',
            right: ''
        },
        defaultView: 'month',
        editable: true,
        allDaySlot: false,
        selectable: true,
        events: eventsArray,
        eventLimit: 1,

        eventLimitClick: function (cellInfo, jsEvent) {
            $(this).popover({
                html: true,
                placement: 'bottom',
                container: 'body',
                title: function () {
                    return $("#events-popover-head").html();
                },
                content: function () {
                    return $("#events-popover-content").html();
                }
            });

            $(this).popover('show');
        },
        dayClick: function (cellInfo, jsEvent) {
            $(this).popover({
                html: true,
                placement: 'bottom',
                container: 'body',
                title: function () {
                    return $("#events-popover-head").html();
                },
                content: function () {
                    return $("#events-popover-content").html();
                }
            });

            $(this).popover('show');
        },
    })

});
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.3.1/fullcalendar.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.3.1/fullcalendar.js"></script>

<div style="border:solid 2px red;">
    <div id='calendar'></div>
    <div id="events-popover-head" class="hide">Events</div>
    <div id="events-popover-content" class="hide">Test</div>
</div>


Solution

  • In the eventLimitClick event change following:

    $(this).popover
    

    To

    $(cellInfo.dayEl)
    

    cellInfo.dayEl is the clicked Day cell element for which you want to show popover.

    I have updated the Fiddle also