(function ($) { Drupal.behaviors.commentNotify = { attach: function (context) { //check the status of the checkbox after page is loaded //is the checkbox checked, show form if ($('input[id^=edit-notify]', context).attr('checked') ) { $('div[id^=edit-notify-type]', context).show(); console.log('show form'); } else { //else hide the form $('div[id^=edit-notify-type]', context).hide(); } //show hide on checkbox on clicks $('input[id^=edit-notify]', context).bind('change', function() { //is the checkbox checked, show form if ($('input[id^=edit-notify]', context).attr('checked') ) { $('div[id^=edit-notify-type]', context).show(); } else { //else hide the form $('div[id^=edit-notify-type]', context).hide(); } }); } } })(jQuery);