0

I need to select the table cell, that has a comment, which contains the word "Baseline EUI" and in that cell I need to add unit name next to the value ("59") like km or miles etc. How do I select the cell, provided the only thing that uniquely identifies that table cell is the keyword inside the comment i.e. "Baseline EUI" ? Please help me how I can select this table cell using jQuery? (I need to add unit like Km or Miles right after the number 59 in the table cell)

<tr>
    <td width="165" class="ms-formlabel" noWrap="nowrap" vAlign="top">
        <H3 class=ms-standardheader><A name=SPBookmark_BaselineEUI></A>Baseline EUI</H3>
    </td>
    <td width="450" class="ms-formbody" id="SPFieldNumber" vAlign="top">
        <!-- FieldName="Baseline EUI" FieldInternalName="BaselineEUI" FieldType="SPFieldNumber"  -->
          59
    </td>
</tr>
<tr>
 There are many rows/cells like the above...
</tr>
Athapali
  • 1,091
  • 4
  • 25
  • 48

2 Answers2

1

First you select the tr tag then loop throw the contents of each tr tag searching for the content which contains the word you are searching for .

$( "tr" ).each(function() {

});

For adding the unit you want, you would do the same but when you find that cell, you will the index method of jquery to know where the number is and then use jquery substring method to split the value of that cell in two parts adding your unit to the first part and then make the value of that cell = the first part (after adding your unit) + the second part (using jquery substring method).

Please, let me know in the comments if you need detailed code .

Alaa Othman
  • 1,109
  • 12
  • 16
1

I haven't test this code. But it should work in your case. please verify and make necessary changes.

$.each($("yourtable tr"),function(i,val){
var check=false;
//check if Baseline EUI is contained inside tr
if($(val).html().indexOf('Baseline EUI'))
{
var x=$(val).find('td')[1];
var p=$(x).html()+' km';//set your suffix
$(x).html(p)

}

});

or use this as a selector of the right tr:

$(".ms-formtable tr").filter(function (i, v) { if ($(this).html().indexOf('Zugehoerigkeit') > 0) { return this; } })
Teoulas
  • 2,943
  • 22
  • 27
StartCoding
  • 394
  • 5
  • 16