.next()和.addClass()在jquery中不起作用

Kam*_*mal 0 jquery

你好朋友关注的是我的代码

HTML

 <ul>
    <li>
    <div class="input"><input name="" type="checkbox" value="" id="a"/></div>
    <div >Name of the survey goes here | 35 Points - <span>Begin Survey</span></div> 
    </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

jQuery的

<script>
$(document).ready(function(){

    $('#a').click(function(){

    $(this).next('div').addClass('.check_clicked');

    })
})
</script>
Run Code Online (Sandbox Code Playgroud)

CSS

.check_clicked
{
    text-decoration:line-through;
    color:#b6a7a7;
}
Run Code Online (Sandbox Code Playgroud)

我只想检查复选框值,然后类.check_clicked应该适用于下一个div

Thi*_*ter 5

.next()访问下一个兄弟.但是,您的#a元素没有.

你想要的是什么 $(this).parent().next()

您还需要删除.类名 - addClass()只接受类,因此它不需要.在类名前面.

这是一个工作演示:http://jsfiddle.net/DqLRc/
如果取消选中该复选框不应该再次删除该类,只需保持addClass我的toggleClass调用的instad .