Reputation: 856
I have a table as,
<table border="1" id="hide">
<tr id="col">
<th>Company Ticker</th>
<th>SubordinationID</th>
<th>Currency</th>
<th>ThreeM</th>
<th>SixM</th>
<th>NineM</th>
<th>OneY</th>
<th>TwoY</th>
<th>FiveY</th>
<th>TenY</th>
<th>FifteenY</th>
<th>TwentyY</th>
<th>ThirtyY</th>
</tr>
<%
Connection connection2 = ConnectionFactory.getConnection();
Statement statement2 = connection.createStatement();
ResultSet resultSet2 = statement
.executeQuery("select * from CDSCURVE");
%>
<tr id="row">
<td id="a">Dummy1</td>
<td id="b">Dummy2</td>
<td id="c">Dummy3</td>
<td id="d">Dummy4</td>
<td id="e">Dummy5</td>
<td id="f">Dummy6</td>
<td id="g">Dummy7</td>
<td id="h">Dummy8</td>
<td id="i">Dummy9</td>
<td id="j">Dummy0</td>
<td id="k">Dummy11</td>
<td id="l">Dummy12</td>
<td id="m">Dummy13</td>
</tr>
</table>
here i want to get the value of id attribute named (a,b,c,d,e,f,g...) in a variable. Need help to create jquery function
one more thing i have multiple rows with different id's then how can retrieve id of the columns specific to that row.
Upvotes: 0
Views: 3626
Reputation: 6158
Try this one
var id = [];
var values = [];
$("#row > td").each(function(index){
id.push($(this).attr("id")); // [a,b,c,....]
values.push($(this).text()); //[ Dummy1, Dummy2, Dummy3, Dummy4,..]
});
Upvotes: 1
Reputation: 1284
I would do something like this:
var result = []
var id = $('#row').children();
for (i=0, i < id.length(), i++){
r = id[i].attr('id')
result.push(r)
};
final = result.join('');
it might be to much tequila this night
Upvotes: 0
Reputation: 14827
You can push all your ids into an array like this:
var IdArray = [];
$("#row").find("td").each(function(){
IdArray.push(this.id);
});
var IdArray = $("#row").find("td").map(function() {
return this.id;
}).get(); //["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"]
Upvotes: 2
Reputation: 12711
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(document).ready(function () {
$("#hide tr td").click(function () {
var id = this.id;
alert($("#" + id).html());
});
});
</script>
Upvotes: 0
Reputation: 779
Go through jquery selectors.
You should try something like this
var arrayVar = new Array();
$("#hide").find("td").each(function(){
alert($(this).attr("id"));
arrayVar.push($(this).attr("id"));
});
Upvotes: 0