Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  120] [ 7]  / answers: 1 / hits: 21095  / 12 Years ago, fri, june 15, 2012, 12:00:00

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


More From » jquery

 Answers
13

I'm not entirely sure what you're trying to achieve here, so please forgive me if my answer isn't what you were looking for. If you want a button which changes the state of a checkbox, then @thecodeparadox's answer should work great, however if you're looking for a button which performs a function but also has a checkbox inside of it which can be toggled, you might want something like the following:



HTML:



<div id=button href=#>
<input type=checkbox class=check>Submit
</div>​


CSS:



body {
margin: 10px;
}
#button {
display: inline-block;
background: #ddd;
border: 1px solid #ccc;
padding: 5px 10px;
text-decoration: underline;
color: blue;
cursor: pointer;
}
.check {
display: inline-block;
margin-right: 10px;
}


jQuery:



$('#button').on('click', function() {
window.location = '#';
})​


http://jsfiddle.net/QStkd/278/


[#84882] Thursday, June 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leonardok

Total Points: 114
Total Questions: 94
Total Answers: 103

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
;