4

I have a checkbox and I am using jquery. I want to popup a dialog box when a user checks the checkbox. However if they uncheck the box nothing should popup.

How can I do this? Also I need to use jquery live or livequery as the checkbox is not displayed on page load.

chobo2
  • 83,322
  • 195
  • 530
  • 832

1 Answers1

14
$('#checkbox').live('change', function(){
    if($(this).is(':checked')){
        popUpFunction();
    }
});
antpaw
  • 15,444
  • 11
  • 59
  • 88
  • Hmm so you can't make a selector that only binds to checked checkboxes? – chobo2 Jun 08 '10 at 19:30
  • sure you can $('input[type="checkbox"]:checked') but this doesnt make sens to me, because checkboxes can change their status. – antpaw Jun 09 '10 at 09:36
  • 6
    Note 2013, _live_ is now deprecated in favor of _on_ . See http://stackoverflow.com/questions/11115864/whats-wrong-with-the-jquery-live-method/11115926#11115926 – Benjamin Gruenbaum Mar 04 '13 at 14:19