Robert Ross Robert Ross - 1 year ago 99
HTML Question

Getting text from html table with jQuery

I am trying to implement some edit/update functionality in my project and I am having hard time accessing the td's in the pricture below.
Firstly, I am not sure if having a class for each is a good idea at all, but this is how I did it.
On each row I have an edit button, which, when pressed is supposed to get the info for the specific row. With my code this works only for the first row.

I have the following structure in the dom :

enter image description here

I tried to access the elements in this way :

$('#lblEditDeleteProducts .brandDom').eq(0).text();

But the problem is that this always gets the text from the first row and I have many rows.

I also tried this code, which didn't work :


Answer Source

The selector is completly wrong:

var i = 1;
$('#lblEditDeleteProducts tr').eq(i).find('.brandDom').text();

Select firstly #lblEditDeleteProducts tr to detect the parent of all elements then find your child using .find(). Using the .eq() make you select the x-index of the selected elements.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download