Question

I would like to fire an ajax script via jQuery, but only after confirmation. I found a nice javascript that works with bootstrap, but can't get it to work. I can get it work when working with a link or with a submit button, but not with another jQuery event. Here is what I have on Fiddle

$(".deleteit").popConfirm({
    placement: "left"
});

$(".deleteit").click(function() {
    alert("aaa");
});

Thanks a lot for any advice! Any other solution with Bootstrap popovers is appreciated as well!

M.

Was it helpful?

Solution

Working Fiddle. And quick view:

 <div style="width: 500px; text-align:center" id="asd">
    <a href="#15" class="btn btn-danger deleteit" role="button">x</a><br />
    <a href="#16" class="btn btn-danger deleteit" role="button">x</a>
</div>

And javascript:

    $(document).ready(function(){
    $('.deleteit').each(function( index ) {
        $(this).popConfirm({
            placement: "left",
            content: '<input class=\'hidId\' type=\'hidden\' value=\'' + $( this ).attr('href') + '\' />'
        });
    });

    $('#asd').on('click','.popover-content .confirm-dialog-btn-confirm', function(e) {
        alert('ajax ID:' + $(e.target).closest('div.popover-content').find('input:hidden').val()); 
        //alert($(e.target).parent().parent().find('input:hidden').val());
         return false;
        }
    );
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top