Digital Legend
Digital Legend

Reputation: 149

Ajax checkbox checked wont work

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();   
   });   
});   

Upvotes: 0

Views: 1731

Answers (3)

Eternal1
Eternal1

Reputation: 5625

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.

Upvotes: 0

Adil Shaikh
Adil Shaikh

Reputation: 44740

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

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

Upvotes: 1

Knelis
Knelis

Reputation: 7139

This should work:

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

Upvotes: 1

Related Questions