Get First Cell In A Row Using Javascript
Here's the first few lines of my code: $('tr.existing_users > td').click(function(e){ var target_name= e.target; var first_element=target_name.parent.first; //wrong e.
Solution 1:
var first_element = $(this).parent().children().eq(0);
var first_html = first_element.html();
Solution 2:
$('tr.existing_users').on("click", function(e){ //listen for click on trconsole.log($(this).find("> td").eq(0).html()); //find children tds and get first one
});
Solution 3:
$(e.target).closest('tr').children().first().html();
This solution keeps your existing click selector and will always give you the html of the first element within the first parent tr
.
Solution 4:
You can use closest() along with find() and :eq() selector:
$('tr.existing_users > td').click(function(e){
var first_element = $(this).closest('tr').find(':eq(0)').html();
});
Post a Comment for "Get First Cell In A Row Using Javascript"