Reputation: 2269
<table id="tab">
<tr><td><input type="checkbox"></td><td aaa="111">sdf</td><td bbb="222">sdfsd</td><td ccc="333">trs</td></tr>
<tr><td><input type="checkbox"></td><td aaa="342">hjk</td><td bbb="274">sdfsd</td><td ccc="337">sdg</td></tr>
<tr><td><input type="checkbox"></td><td aaa="432">hgj</td><td bbb="652">sdfsd</td><td ccc="747">dih</td></tr>
</table>
<span id="show">show</span>
$("#show").click(function(){
var text = [];
$("#tab").each(
if($(this).find(input[type=checkbox].is(:checked))){
text.push({
'aaa': $(this).attr('aaa'),
'bbb': $(this).attr('bbb'),
'ccc': $(this).attr('ccc')
});
}
)
console.log(text);
})
LIVE: http://jsfiddle.net/KFbbZ/
If i click show i would like get all parameters form checked TR. How can i make it? My example is bad...
Upvotes: 1
Views: 182
Reputation: 69915
Try this
var text, $tr, $td, isChecked;
$("#show").click(function(){
text = [];
$("#tab input:checked").each(function(){
$tr = $(this).closest('tr');
$tds = $tr.find('td');
text.push({
'aaa': $tds.eq(1).attr('aaa'),
'bbb': $tds.eq(2).attr('bbb'),
'ccc': $tds.eq(3).attr('ccc')
});
});
console.log(text);
})
Upvotes: 3
Reputation: 981
You are looping through instances of tables with ID "tab"
when really you want to be looping through all checked boxes:
var $boxes = $('table#tab').find('input[type="checkbox"]:checked');
$boxes.each(function() {
text.push({
'aaa': $(this).attr('aaa'),
'bbb': $(this).attr('bbb'),
'ccc': $(this).attr('ccc')
});
});
Upvotes: 1