문제

I am trying to assign popover from twitter bootstrap to an element which is loaded via ajax and I have this:

        $(document).on("click", ".checkRezolvataTrecut", function(event){
        switch(dataCheckTrecut[1]) {
            case '02': 
                var luna = "Februarie";
                break;
        }
        $(".checkRezolvataTrecut").popover({
            placement: "top",
            content: "<button class='btn btn-default mutaTrecut' style='width: 100px;'>" + luna + "</button><button class='btn btn-default mutaCurent' style='width: 100px;'>Luna curenta</button>",
            html: true

        });
    });

The problem is that on first click nothing happens. After the first click it works. As a mention, I didn't understood bootstrap js too well. Any ideas?

도움이 되었습니까?

해결책

It's normal that on the first click nothing happens, because it's on the first click that you are setting the popover, once set (in the first click) the popover will show in the next clicks,

if you want it to show on the first click you should set the popover when jquery is ready :

$( document ).ready(function() {
   switch(dataCheckTrecut[1]) {
        case '02': 
            var luna = "Februarie";
            break;
    }
    $(".checkRezolvataTrecut").popover({
        placement: "top",
        content: "<button class='btn btn-default mutaTrecut' style='width: 100px;'>" + luna + "</button><button class='btn btn-default mutaCurent' style='width: 100px;'>Luna curenta</button>",
        html: true

    });
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top