Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use stopPropagation() to fix this

example jsfiddle

something like

$('#accordion input[type="checkbox"]').click(function(e) {
    e.stopPropagation();
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...