Aditya
Aditya

Reputation: 75

Fetching the innerHTML from TD in jQuery

Hi I am using Sharepoint 2010 page, where I have the HTML snipet with the following structure:

<tr>
  <td></td>
  <td class="ms-vb2"></td>
  <td class="ms-vb2"></td>
  <td class="ms-vb2"></td>
  <td class="ms-vb2"></td>
  <td class="ms-vb2"><nobr><b>Sum= 72</b></nobr></td>
  <td class="ms-vb2"><nobr><b>Sum= 66</b></nobr></td>
</tr>

Now I want to get the value 72 and 66 from the TD tag in a var, so that I can use these values in the client scripts.

The "Sum=" part of the TD is not supposed to change. And the ID of the table is randomly generated by sharepoint so I can't do anything with that as well.

Please help.

Thanks,

Upvotes: 0

Views: 5259

Answers (3)

Aditya
Aditya

Reputation: 75

Here is the solution- took time for me to generate the same.. :)

 var arrValue = "";
    $('td.ms-vb2').filter(function (i) {
        if ($(this).html().indexOf('Sum=') > 0) {

            mystring = $(this).html();
            var result = /\d+(?:\.\d+)?/.exec(mystring);
            //console.log(arrValue)
            arrValue = result[0] + "," + arrValue
        }
    });

Thanks

Upvotes: 0

Pandian
Pandian

Reputation: 9126

Try like below, It will help you..

Fiddle : http://jsfiddle.net/RYh7U/150/

$('td.ms-vb2').each(function() {    
    var value = $(this).text();
    if(value !="")
     alert(value);
    //If you want to replace the Sum= in Text then try the below code
    $(this).text($(this).text().replace("Sum= ",""));
});

Upvotes: 0

flavian
flavian

Reputation: 28511

$(".ms-vb2 b").each(function(td) {
   var s = td.hmtl().replace("Sum= ", "");
    $("body").append(s);
});

Here's the working fiddle.

Upvotes: 1

Related Questions