Skip to content

It is odd when using "attr" on checkbox, it works on the first time only #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LeonLi0102 opened this issue May 7, 2015 · 5 comments
Closed

Comments

@LeonLi0102
Copy link

<textarea>




<title>Checkbox Test</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
    $().ready(function(){       
        $("#checkControl").click(function(){            
            // It is odd it works only on the first time whey you click 'All/None'  
             $("input[name='check_items']").attr("checked",this.checked);
             
            // I know this will work, but still the code above is confused me.
            // $("input[name='check_items']").prop("checked",this.checked);
             
        });     
    });     
    </script>


All/None

item1
item2
</textarea>
@AchoArnold
Copy link
Contributor

@LeonLi0102 Please can you provide a test case? Everything works fine here http://jsfiddle.net/129d9ubc/1/

@scottgonzalez
Copy link
Member

Please read the documentation about boolean attributes on http://api.jquery.com/attr/.

@LeonLi0102
Copy link
Author

<textarea>




<title>Checkbox Test</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
    $().ready(function(){       
        $("#checkControl").click(function(){            
            // It is odd it works only on the first time whey you click 'All/None'  
             $("input[name='check_items']").attr("checked",this.checked);
             
            // I know this will work, but still the code above is confused me.
            // $("input[name='check_items']").prop("checked",this.checked);
             
        });     
    });     
    </script>


All/None

item1
item2
</textarea>

@AchoArnold
Copy link
Contributor

@LeonLi0102 Please read the documentation pointed by @scottgonzalez and you'll understand

@LeonLi0102
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants