Click on a div to toggle a checkbox inside of it using javascript

前端 未结 6 907
耶瑟儿~
耶瑟儿~ 2020-12-15 18:50

This seems to be a simple problem, but I dont use alot of javascript.

I have a div, with a checkbox in it, and would like the whole div to toggle the checkbox. This

6条回答
  •  忘掉有多难
    2020-12-15 19:26

    It's possible you could implement this in a more robust and accessible way by using the label element to wrap the area you want to click.

    For example:

    
    

    I haven't tested the above code, but I believe all browsers support clicking of labels to check an input box.

提交回复
热议问题