Question

I have a checkbox with id #cond99; it's loaded form ajax, and that's working okay but I want to add an action and it's not working. Can anyone help me?

jQuery = window.parent.jQuery;   
jQuery(document).ready(function ()   
{    
   jQuery('input.styled').iCheck(   
   {    
       checkboxClass: 'icheckbox_minimal-orange',   
       radioClass: 'iradio_minimal-orange',  
       increaseArea: '40%' // optional  
   });      
   jQuery('input.styled').iCheck('update');   
   jQuery("#cond999").bind("change", function ()  
   {   
       jQuery('#conditions_more').toggle();   
   });   
});   
Was it helpful?

Solution

If it's loaded dynamically you can use event delegation -

jQuery(document).on("change","#cond999", function () {
      jQuery('#conditions_more').toggle();
});

OTHER TIPS

This should work:

jQuery(document).on('change', '#cond999', function () {
    jQuery('#conditions_more').toggle();
});

If you're inserting your #cond999 element as an Ajax, it might not be available when document.ready event fires, and therefore, you cant bind anything to it.

You might consider binding this event at a callback of an Ajax request that inserts the checkbox into the code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top