suhail suhail - 10 months ago 42
Javascript Question

I want to redirect to link on <a> only after confimation?

I had a problem and I am struggling. I want to redirect to the link

href="/jobs/emp/del/?id={{ }}"
after confirmation. I am using

{% for job in jobs %}
<a class="btn deleteJob" href="/jobs/emp/del/?id={{ }}"</a>
{% for job in jobs %}

How can I require confirmation before executing the link
/jobs/emp/del/?id={{ }}

I tried:

<a class="btn deleteJob"><span style="display:none">/jobs/emp/del/?id={{ }}</span>
<i class="icon-trash"></i></a>
<script src="/static/js/bootbox.js" type="text/javascript"></script>

bootbox.confirm("Are you Sure want to delete!", function (x) {
if (x){

var link= $(this).find( $spans ).text();

is inside a big for loop, but it is not working!?


I've not used bootbox, but assuming the x value in the function is the boolean result of the popup, this should work:

<a href="/jobs/emp/del/?id={{ }}" class="btn deleteJob">
    <i class="icon-trash"></i>
$('.deleteJob').click(function(e) {
    var $link = $(this);
    bootbox.confirm("Are you Sure want to delete!", function (confirmation) {
        confirmation && document.location.assign($link.attr('href'));

Note, you mention a for loop - the jQuery code there does not need to be in a loop. That code will work for all instances of the .deleteJob anchor element.