如何从点击事件中分配子元素

sas*_*asa 4 javascript jquery

有人可以帮我这个.有HTML代码:

<h3>
    <label>
        <input type="checkbox" name="country" value="us" /> United States
    </label>
</h3>
<p>Some content goes here</p>
Run Code Online (Sandbox Code Playgroud)

我想切换p通过点击元素H3标签,但我不wan't切换,如果我点击了上标签

$('h3').click(function() {
   // Does something goes here?
   $(this).next('p').toggle();
}
Run Code Online (Sandbox Code Playgroud)

fea*_*age 17

您需要检查操作的目标

$('h3').click(function(e) {
   // if they clicked the h3 only
   if (this == e.target) {
     $(this).next('p').toggle();
   }
}
Run Code Online (Sandbox Code Playgroud)

altCognito的建议也可以,但它是更多的代码.