I have a accordion table and I want to get the all the id values of tr using jquery
<div id="acc22" class="accBox">
<p class="accordianHead">
<div class="accordianBody">
<form id="form_22" action="" method="post" encoding="">
<div style="display:none;">
<table id="item_tbl_22" class="accTable" cellspacing="0" cellpadding="0" border="0" width="100%">
<thead class="greyBg paddingHead">
<tbody>
<tr id="S3639-1-1_824" style=" ">
<tr id="S3639-1-2_824" style=" ">
<tr id="S3639-1-3_824" style=" ">
<tr>
</tbody>
</table>
</form>
</div>
How to get the id value of tr using jquery
This way you can create an array of your tr id's using jQuery.
var idArray = [];
$('table#item_tbl_22 > tbody > tr').each(function() {
if($(this).prop('id')) {
idArray.push($(this).prop('id'));
}
});
console.log(idArray);
// Same result Using jQuery map() as well
var idArray_1 = [];
$('table#item_tbl_22 > tbody > tr').map(function() {
if($(this).prop('id')) {
idArray_1.push($(this).prop('id'));
}
});
console.log(idArray_1);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="acc22" class="accBox">
<p class="accordianHead">
<div class="accordianBody">
<form id="form_22" action="" method="post" encoding="">
<div style="display:none;">
<table id="item_tbl_22" class="accTable" cellspacing="0" cellpadding="0" border="0" width="100%">
<thead class="greyBg paddingHead">
<tbody>
<input id="cloth_id22" type="hidden" value="72" name="fabric_id">
<input id="cloth_colour_id22" type="hidden" value="824" name="data[Cloth][cloth_id]">
<tr id="S3639-1-1_824" style=" ">
<tr id="S3639-1-2_824" style=" ">
<tr id="S3639-1-3_824" style=" ">
<tr>
</tbody>
</table>
</form>
</div>
</div>