javascript - can't get .on() to work -
i know topic has been asked lot before read lot of stackoverflow posts , can't figure out. either i'm doing silly mistake or using code wrong. in case i'd appreciate other sets of eyes.
my code simple. elements being dragged boxes , want user able close dragged boxes can redo dragging.
<div id="questioncontainer"> <div class='row-fluid'> <div class='span3 box-content'> <div class="box span12"> <input type="text" placeholder="column 1" /> </div> <div class="box span12 groupboxes"> </div> </div> <div class='span3 box-content'> <div class="box span12"> <input type="text" placeholder="column 2" /> </div> <div class="box span12 groupboxes"> </div> </div> <div class='span3 box-content'> <div class="box span12"> <input type="text" placeholder="column 3" /> </div> <div class="box span12 groupboxes"> </div> </div> <div class='span3 box-content'> <div class="box span12"> <input type="text" placeholder="column 4" /> </div> <div class="box span12 groupboxes"> </div> </div> </div>
then there javascript appends dragged element. , have .on() function there doesn't work @ all.
$( ".groupboxes" ).droppable({ accept: ".sdrag", drop: function( event, ui ) { var studentid = $(ui.draggable).attr('uid'); var studentname = $(ui.draggable).find(".sname").text(); console.log(studentid + ' ' + studentname); var dropbox = "<div class='box questionbox' uid='"+studentid+"' ><div class='box-content box-statistic'><h3 class='title text-error'>"+studentname+"</h3><div class='icon-remove align-right card-remove' style='font-size:12px'></div></div> </div>"; $(this).append(dropbox); } }); $("#questioncontainer").on('click', '.card-remove', function () { console.log('hi'); var student = $(this).parent('.questionbox').attr('uid'); // user number var box = $(".studentbox[value='"+student+"']")// find original object through user box.removeclass('muted-background').addclass('sdrag');// in original object, add class sdrag , remove class muted-background // remove object clicked });
any ideas what's going wrong here?
try define dropbox outside function
var dropbox; $( ".groupboxes" ).droppable({ accept: ".sdrag", drop: function( event, ui ) { var studentid = $(ui.draggable).attr('uid'); var studentname = $(ui.draggable).find(".sname").text(); console.log(studentid + ' ' + studentname); dropbox = "<div class='box questionbox' uid='"+studentid+"' ><div class='box-content box-statistic'><h3 class='title text-error'>"+studentname+"</h3><div class='icon-remove align-right card-remove' style='font-size:12px'></div></div> </div>"; $(this).append(dropbox); } }); $("#questioncontainer").on('click', '.card-remove', function () { console.log('hi'); var student = $(this).parent('.questionbox').attr('uid'); // user number var box = $(".studentbox[value='"+student+"']")// find original object through user box.removeclass('muted-background').addclass('sdrag');// in original object, add class sdrag , remove class muted-background // remove object clicked });
Comments
Post a Comment