Help with unit testing checkbox behavior. I have this page:
How about using change
instead of click
?
$('#makeHidden').change(function() {
var isChecked = $(this).is(':checked');
if (isChecked) {
$('#displayer').hide();
}
else {
$('#displayer').show();
}
return false;
});
The return false;
won't be in the way since the event is fired as a result of the change having occurred.
Here is a work around.
Now my code is like this:
if ($.browser.msie) {
$('#makeHidden').change(function () {
this.blur();
this.focus();
onCheckboxClicked();
});
}
else {
$('#makeHidden').change(function() {
return onCheckboxClicked();
});
}
All my tests including manual toy and manual production are good.
Anybody have something better than this hack?
Try this:
$(function() {
$('<div><input type="checkbox" name="makeHidden" id="makeHidden" checked="checked" />Make Hidden</div>').appendTo('body');
$('<div id="displayer" style="display:none;">Was Hidden</div>').appendTo('body');
$('#makeHidden').click(function() { return onCheckboxClicked(this) } );
});
function onCheckboxClicked(el) {
var isChecked = $(el).is(':checked');
if (isChecked) {
$('#displayer').hide();
}
else {
$('#displayer').show();
}
return false;
}