Reputation: 1634
I am at a loose end as to why my code is not hiding when i untick. I would be grateful if someone could check my code and point out where I am going wrong. I have posted code here. many thanks
Upvotes: 0
Views: 4408
Reputation: 40863
You can juse use this.checked
$('input[name=messagetick]').click(function() {
if (this.checked) {
$('.contactmessage').show();
}
else {
$('.contactmessage').hide();
}
});
A slightly better version would use .toggle([showOrHide])
$('input[name="messagetick"]').click(function() {
$('.contactmessage').toggle(this.checked);
});
Side note, don't forget your "
when using an attribute selector.
Upvotes: 5
Reputation: 76900
You didn't choose jquery as framework and so mootools was loaded.
use this code:
$('input[name=messagetick]').click(function() {
$('.contactmessage').toggle($(this).is(':checked'));
});
fiddle: http://jsfiddle.net/8k8VW/9/
Upvotes: 2
Reputation: 82933
You can use is(":checked") to see if the checkbox is checked.
Try this:
$('input[name=messagetick]').click(function() {
if($(this).is(":checked")) {
$('.contactmessage').show(); }
else {
$('.contactmessage').hide();
} });
Example @ http://jsfiddle.net/8k8VW/18/
Upvotes: 2