How do you get a value onClick from outside the anchor that is clicked?
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);
});
$('#logNameAndValue').click(function(event){
name = $(this).text();
value = $(this).parent().next().text();
console.log("name=" + name + " value=" + value);
});
name = $(this).text()
value = $('#value_' + $(this).attr('id').substring($(this).attr('id').length-1)).text()
$('#logNameAndValue').click( function(event){
name=$(this).text();
value=$(this).parent().next("td").text();
console.log("name=" + name + " value=" + value);
});
In the click event function, the value would be $(this).siblings('td').text() I believe, and the name would be $(this).text().
精彩评论