1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

jQuery .on() event not firing

Discussion in 'jQuery' started by PoPSiCLe, Feb 9, 2014.

  1. #1
    I have an event (a click on a checkbox) that doesn't work, for some reason.
    This is after a <span> with the checkbox inside is dragged (using ui.draggable) from one <td> to another <td>
    This is the jQuery code pertaining to this particular event:
    
    $('#coordinate_table').on('click', 'input[type=checkbox]',function() {
               var coordinate = 'coordinate';
               var isShiftleader = $(this).parent('span').hasClass('shiftleader');
               var userID = $(this).val();
               postDraggedName = $(this).attr('name');
               var params = { };
               params[coordinate] = 'yes';
               params['studentid'] = userID;
               if ($(this).is(':checked')) {
                   params[postDraggedName] = "on";
                   params['workdate'] = postDraggedName;
               } else {
                   params[postDraggedName] = "off";
                   params['workdate'] = postDraggedName;
               }
             if ($(this).is(':checked')) {
               console.log(params);
             } else {
               console.log(params);
             }
             $.post("timesheet/timesheet_register.php",params,function(data) { if (data != "") {
               showUpdateInfo(data,'success');
                 }
               });
           });
    });
    
    Code (javascript):
    The HTML-code is a bit more complicated, but it's something like:
    
    <table id="coordinate_table">
    <tbody>
      <tr>
         <td class="droppable">
             <span class="draggable"><input type="checkbox"></span>
         </td>
      </tr>
    </tbody>
    </table>
    
    Code (markup):
    I want to note that the click-event on the checkbox works BEFORE the <span> is dragged - but not after. Shouldn't the .on()-event deal with this?
     
    PoPSiCLe, Feb 9, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    And... I feel stupid now. The .on()-event didn't fire due to another CSS-styling set using labels to change the look of the checkbox itself - hence you're clicking the <label>, not the <input> - and of course the event didn't fire. Fixed now.
     
    PoPSiCLe, Feb 10, 2014 IP
  3. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #3
    I was about to suggest that. Are you using jQuery mobile, Bootstrap or Foundation by any chance?
     
    HuggyStudios, Feb 10, 2014 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Nope - neither of those, as of yet, although I'm looking into applying something for mobile - however, I'm probably just gonna do that mostly in CSS
     
    PoPSiCLe, Feb 10, 2014 IP