Robert Ross Robert Ross - 1 year ago 72
jQuery Question

Getting a value from table with jQuery

I am trying to get a value from my table cells using jQuery. I am new to jQuery and I tried many things, but nothing gave me the sought result.
Below are some examples of what I've tried so far.
I simply want to get the text between the tags.

The DOM looks like this :
enter image description here

I tried with :

$("tr td:nth-child(3)").text();

Which got me :


I also tried with :


But this resulted in nothing.

Any input will be appreciated.

Answer Source

$("tr td:nth-child(3)").text();

This gets you every 3rd td in every tr, thats why you're getting all that text appended.

After you convert all the columns id to class.. You can do something like this:

$('#lblEditDeleteProducts .priceDom').eq(0).text()

Using the image in your question, this would return 123

To explain the selector:

$('#lblEditDeleteProducts .priceDom') this will return an array of all the elements with class of priceDom inside the element with id lblEditDeleteProducts.

.eq(0) this will return the first element in the array from above

.text() this will return the text of the element above

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