Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialnicholas maddren
12,793 PointsMake checkbox container clickable
Hey guys, I'm a little confused at the moment.
How can I make the container of the checkbox clickable?
Here is an example of my form: http://jsfiddle.net/7r4pzbzg/1/
As you can see only the checkbox and the label is clickable, how can I make the actual container that it sits in clickable? I have tried making the label width 100% however it sits on a different line when that is done.
Any ideas? Thanks
2 Answers
Jay Mayu
6,805 PointsCheckout this solution at http://jsfiddle.net/7r4pzbzg/4/
This is where the decision is made and checkbox checked / unchecked
$('.panel').on('click',function(){
if(checkBoxChecked){
checkBoxChecked = false;
$('#bodytype-checkbox').prop('checked', false);
}else{
checkBoxChecked = true;
$('#bodytype-checkbox').prop('checked', true);
}
});
I declared a global boolean variable to track whether the checkbox is checked or not. if it's checked then I programmatically uncheck it and viceversa.
Geert-Jan Hendriks
23,126 Pointsyou could set your label to a block element. This pushes the checkbox away, but you can float the checkbox to the left. Try to add this to your css:
label{
display: block;
padding-left: 20px;
}
#bodytype-checkbox{
float:left;
}
nicholas maddren
12,793 Pointsnicholas maddren
12,793 PointsHey, thanks I tried it and it works well however the label cannot be clicked to check the box :(
Jay Mayu
6,805 PointsJay Mayu
6,805 PointsI hope this one helps :)
http://jsfiddle.net/7r4pzbzg/11/