SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to get the text from the first and second TD which has the class user and id

<tr class="rowid">
    <td class="user">A</td>
    <td class="id">B</td>

So first i want A and then B I tried

 $(".rowid").each(function(index, value) { 
var test= $(.user).text();

But i get A twice.I want one value at a time. Any ideas what 'm doing wrong? Cheers

share|improve this question
Here's complete tutorial how to get table cell TD value – Satinder singh Jul 20 at 10:44
up vote 2 down vote accepted

This piece of code is always pointing to A:

var test = $(".user").text()

instead use:

$(".rowid").find("td").each(function() {
  var test = $(this).text();

this will iterate over the td elements and output the text.

To get each value:

$(".rowid").each(function() {
  var a = $(this).find(".user").text();
  var b = $(this).find(".id").text();
share|improve this answer
Thanks Russel I do i get "A" and "B" seperately. Chrs – naijacoder Jan 19 '12 at 0:41
I have added a block of code so you can iterate over each tr element and return the user and id (A and B text) for each one. Is that what you are trying to do? – Russell Jan 19 '12 at 1:47
Chrs Russell. Hope to be on top off Jquery soon – naijacoder Jan 19 '12 at 4:16
No worries. :) Good luck! – Russell Jan 19 '12 at 4:59

First selector ".rowid" selects all tags with class "rowid". At you markup example it's only one tr tag, so you will itterate by each function only through one element. Second selector ".user" gives you all tags with class "user", but if you want to take A and then B, will need to take all td tags of current tr container or select ".user" td and ".id" td seperatly as in example below.

    rows = $(".rowid").each(function(index,value){
            user = $(value).children(".user").text();
            id = $(value).children(".id").text();
share|improve this answer
IAfanasov thanks tried it but didn't work – naijacoder Jan 19 '12 at 0:38
<table id ="table1">
        <td id = "1">username</td>
        <td id = "2">12344</td>

$('#table1 tr').each(function (){
    var vara = $(this).find('#2').html();
    if(vara != null)
share|improve this answer
Please add some explanation when answering, rather than just dropping a code fragment. This will make your answer much more useful. Thanks. – SPDoctor Nov 27 '12 at 23:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.