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();   
   });   
});   
有帮助吗?

解决方案

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

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top