javascript - jQuery selector not working correctly -
so here html:
<div class="alert alert-info alert-warning" id="rowcounter" style="display: block; bottom: -22px;"> sure want delete 103? <div class="btn-toolbar"> <a href="#" class="btn btn-sm btn-success" data-action="deleterow" data-table="contact" data-rowid="103">yes</a> <a href="#" class="btn btn-sm btn-default" data-action="cancel">no</a> </div> </div>
and jquery (wrapped in script tags , document ready function):
$('.alert#rowcounter a.btn').on('click',function() { console.log('yes'); if($(this).data('action') == 'cancel') { rowcounter('hide'); } if($(this).data('action') == 'deleterow') { var tbl = $(this).data('table'); var targ = $(this).data('rowid'); $.get('formhandler.php?handle=deleterow&table='+tbl+'&rowid='+targ,function(d) { if(d == 'success') { $('#rowcounter').removeclass().addclass('alert alert-success').html('successfully removed '+targ+'!'); } }); } });
for whatever reason, jquery not selecting buttons within toolbar , i'm not sure why. if can give me reason why isn't working it'd appreciated!
use #rowcounter a.btn instead of .alert#rowcounter a.btn
$('#rowcounter a.btn').on('click',function() { console.log('yes'); if($(this).data('action') == 'cancel') { rowcounter('hide'); } if($(this).data('action') == 'deleterow') { var tbl = $(this).data('table'); var targ = $(this).data('rowid'); $.get('formhandler.php?handle=deleterow&table='+tbl+'&rowid='+targ,function(d) { if(d == 'success') { $('#rowcounter').removeclass().addclass('alert alert-success').html('successfully removed '+targ+'!'); } }); } });
Comments
Post a Comment