Reputation: 3439
Assuming the following HTML:
<tr id="record_1" >
<td id="name_1"><a href="#" id="logNameAndValue">Charles Dickens</a></td><td id="value_1">A Christmas Carol</td>
</tr>
How can I print out name=Charles Dickens value=A Christmas Carol
by partially using the following jQuery:
$('#logNameAndValue').click( function(event){
name=?
value=?
console.log("name=" + name + " value=" + value);
});
Upvotes: 0
Views: 604
Reputation: 2199
$('#logNameAndValue').click( function(event){
name=$(this).text();
value=$(this).parent().next("td").text();
console.log("name=" + name + " value=" + value);
});
Upvotes: 1
Reputation: 2312
name = $(this).text()
value = $('#value_' + $(this).attr('id').substring($(this).attr('id').length-1)).text()
Upvotes: 1
Reputation: 101614
In the click event function, the value would be $(this).siblings('td').text() I believe, and the name would be $(this).text().
Upvotes: 0
Reputation: 245429
$('#logNameAndValue').click(function(event){
name = $(this).text();
value = $(this).parent().next().text();
console.log("name=" + name + " value=" + value);
});
Upvotes: 2