I am looking to get all checkboxes' VALUE which have been selected through jQuery.
            Asked
            
        
        
            Active
            
        
            Viewed 1.4e+01k times
        
    77
            
            
        - 
                    1what do you mean by `selected through jquery`? – Arun P Johny Nov 04 '13 at 10:54
- 
                    Refer this article: http://javascriptstutorial.com/blog/get-selected-checkbox-values/ – Dilip Kumar Yadav Nov 02 '16 at 06:33
1 Answers
265
            You want the :checkbox:checked selector and map to create an array of the values:
var checkedValues = $('input:checkbox:checked').map(function() {
    return this.value;
}).get();
If your checkboxes have a shared class it would be faster to use that instead, eg. $('.mycheckboxes:checked'), or for a common name $('input[name="Foo"]:checked')
- Update -
If you don't need IE support then you can now make the map() call more succinct by using an arrow function:
var checkedValues = $('input:checkbox:checked').map((i, el) => el.value).get();
 
    
    
        Rory McCrossan
        
- 331,213
- 40
- 305
- 339
- 
                    2
- 
                    22
- 
                    1I got comma separated values without using .join('). I am using jQuery 1.10.2. And thanks for saving me time and extra lines of unnecessary lines of code, for me it works just perfect. – zeeshan Jan 09 '14 at 22:43
- 
                    1sorry to say that but it will always annoys me: `this.value`. Once you've started to use jQuery, so let's `return $(this).val();` – vaso123 Mar 01 '17 at 14:45
- 
                    2@vaso123 It's a personal preference as the performance difference is so slight, but I don't see the point creating a jQuery object for a property already available from `this`. – Rory McCrossan Mar 01 '17 at 14:46
- 
                    Not consecvent. A 3rd users come, and starting to implement his own code as he thinkig, let's say add `$` to a jQuery object vairiable, and when a new developer need to maintain the code, he will found `$(this)`, `$this`, `this`, so he need to take time while figure out the puzzle, and refactor this not clean code. But it's your preference... – vaso123 Mar 01 '17 at 15:06
- 
                    4Well, code should be made to the best standards, not the lowest simply so inexperienced developers can understand it. – Rory McCrossan May 11 '17 at 07:13
 
    