javascriptjqueryalertify

alertify making me click twice


I have a HTML rows like this

<div class="wsdRow">
        <div class="ib swsLbl">(new)</div>
        <div class="ib swsLbl"><input type="text" class="wsd"></div>
        <div class="ib swsLbl"><input type="text" class="wsAmount numbersOnly"></div>
        <div class="ib swsLbl">
         <button class="saveWC">save</button>
         <button class="delWC">-</button>
      <div class="wcResult ib"></div>
        </div>
        <div class="clr"></div>
</div>      

<div class="wsdRow">
        <div class="ib swsLbl">(new)</div>
        <div class="ib swsLbl"><input type="text" class="wsd"></div>
        <div class="ib swsLbl"><input type="text" class="wsAmount numbersOnly"></div>
        <div class="ib swsLbl">
         <button class="saveWC">save</button>
         <button class="delWC">-</button>
      <div class="wcResult ib"></div>
        </div>
        <div class="clr"></div>
</div>      

then I bind the delete button like so

$(".delWC").click(function(){ 
        var ths=$(this).parent().parent(".wsdRow");                 
            alertify.confirm("are you sure you want to delete this row?", function (e) {
                if (e) {
                            $(ths).remove();                                            
                } 
            });             
});

for some reason, I have to click the alertify.confirm twice. The first time the user clicks "ok" the row is deleted as expected, but the alert stays until they click again. If they click "cancel", they still need to do it twice otherwise it won't go away.


Solution

  • Try using this

    $('[id^=alertify]').remove();