I have around 9 checkboxes with different rel values. How can I get the all the rel values of checked check boxes in an array or as csv using jQuery?
<input type="checkbox" name="item" rel="WVSEUPU" />
I have around 9 checkboxes with different rel values. How can I get the all the rel values of checked check boxes in an array or as csv using jQuery?
<input type="checkbox" name="item" rel="WVSEUPU" />
Share
Improve this question
edited Feb 12, 2017 at 20:05
marc_s
757k184 gold badges1.4k silver badges1.5k bronze badges
asked Jul 18, 2011 at 8:37
esafwanesafwan
18.1k35 gold badges110 silver badges170 bronze badges
1
- 2 input elements don't have a rel attribute, either use a standard attribute (e.g. class) or an HTML5 data- attribute. – RobG Commented Jul 18, 2011 at 9:27
2 Answers
Reset to default 4var relArr=[];
$("input[type='checkbox']:checked").each(function(){
relArr.push($(this).attr('rel'));
});
here is the working fiddle http://jsfiddle/7zSRQ/
You could do:
var rels = [];
$('input[type="checkbox"]:checked').each(function(){
var rel = $(this).attr('rel');
rels.push(rel);
});
//rels is an array you could use rels.join(',') to join the array.