Check a checkbox on keypress on a label

Tags: javascript css
By : luis

I have the following on angular

<input type="checkbox" id="test"/>
<label for="test">Testing</label>

I'm trying to set a checkbox checked when i press enter on a label while using the tab and the focus is on the label

<input type="checkbox" id="test"/>
<label for="test" ng-click="setCheckBox($event)">Testing</label>

so far i tried using ng-click, ng-keydown or even onclick and nothing happens. i was hoping to achieve this using just css. thanks

By : luis

            $('#mycheckbox').keypress(function(event) {
                var keycode = (event.keyCode ? event.keyCode : event.which);

                if (keycode == 13) {

        function clickCheckBox(box){

                var $box = $(box); 



<input type='checkbox' id='mycheckbox'>dev</input>

look at these two forms

<label><input id="inputone" type="checkbox"/> Testing</label>

<input type="checkbox" id="inputtwo"/>
<label for="inputtwo">Testing 2</label>

I would use the following:

var startIndex = $('.start').index();
var endIndex = startIndex - 5;

for(var i = startIndex - 1; i >= endIndex; i--){

Updated to not add class 'good' the start index.

This video can help you solving your question :)
By: admin