Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox inside button?

Is there any way to get a checkbox inside a button?

At the moment I have this solution:

<html>
<body>
   <div id="menu">
     <button><input type="checkbox" /></button>
   </div>
</body>
</html>

It's ok, it works fine with Chrome and Firefox...but really awful with IE, so I need another way to achieve this goal.

1 2

Any ideas? Thanks

like image 607
Clem Avatar asked Jun 15 '12 06:06

Clem


People also ask

Can I use button on checkbox?

Since the button only adds or removes entities, the user knows the action they will prompt upon click. The checkbox button also provides a clear visual affordance and a large target to take this action. Use the add button if the component you're building: Exists without other multi-select elements (i.e. checkboxes)

How do you insert a checkbox in HTML?

The <input type="checkbox"> defines a checkbox. The checkbox is shown as a square box that is ticked (checked) when activated. Checkboxes are used to let a user select one or more options of a limited number of choices.

How do you check whether a checkbox is checked or not in Javascript?

Checking if a checkbox is checked First, select the checkbox using a DOM method such as getElementById() or querySelector() . Then, access the checked property of the checkbox element. If its checked property is true , then the checkbox is checked; otherwise, it is not.

What is checkboxes in Javascript?

A checkbox allows you to select single values for submission in a form (or not).


1 Answers

I think its not a valid mark up to place a checkbox within a button. It would be better to replace the button with span or div and apply some CSS to span or div to make look like button and apply click event to that and change the checkbox state.

Just an example for you

like image 194
thecodeparadox Avatar answered Oct 15 '22 22:10

thecodeparadox