Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQueryUI accordion with checkboxes

I'm trying to put a checkbox in each of my accordion headings to indicate whether something should be disabled or not. The checkbox shows up fine, however, its not clickable as the whole accordion header is linked to the <a> tag. Putting the checkbox outside the <a> tag makes the checkbox appear underneath the heading, which is not what I want, and it still isn't clickable either.

<div id="accordion">
    <h3><a href="#">Text <span id="id">More text<input type="checkbox"/></span></a></h3>
    <div>content etc</div>
</div>
like image 218
Michael Avatar asked Sep 15 '11 05:09

Michael


3 Answers

<input type="checkbox" onclick="event.stopPropagation()" />
like image 87
Eyal Avatar answered Nov 19 '22 03:11

Eyal


You can use stopPropagation() to fix this

example jsfiddle

something like

$('#accordion input[type="checkbox"]').click(function(e) {
    e.stopPropagation();
});
like image 30
MikeM Avatar answered Nov 19 '22 05:11

MikeM


I would be taking the input control out of the hyperlink.

<h3><a href="#">Text</a><span id="id">More text<input type="checkbox"/></span></h3>
like image 2
alistair Avatar answered Nov 19 '22 03:11

alistair