Overriding check box in JavaScript with jQuery
Posted
by Gutzofter
on Stack Overflow
See other posts from Stack Overflow
or by Gutzofter
Published on 2010-05-20T15:28:03Z
Indexed on
2010/05/20
15:30 UTC
Read the original article
Hit count: 218
Help with unit testing checkbox behavior. I have this page:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(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() {
var isChecked = $(this).is(':checked');
if (isChecked) {
$('#displayer').hide();
}
else {
$('#displayer').show();
}
return false;
});
});
</script>
</head>
<body>
</body>
</html>
This doesn't work it is because of the return false;
in the click handler. If I remove it it works great. The problem is if I pull the click function out into it's own function and unit test it with qunit it will not work without the return false;
© Stack Overflow or respective owner