Question

I need to test if the second cell of any rows with attribute section-name = section2 and second cell containing 'FieldInternalName="BaseLineEUI" ' in the comment node - is empty or not? I simply gave up after this:

jQ("tr[section-name='Section2']").each(function(i){
$(this).children('td').slice(0,2).
 //how do I test if the comment contains a string here?

})

<tr style="display: block;" section-name="Section2">
      <TD class=ms-formlabel vAlign=top width=165 noWrap>
      <H3 class=ms-standardheader>
      <A name=SPBookmark_ClimateZoneASHRAEIECC></A>ClimateZoneASHRAEIECC</H3>
      </TD>
      <TD id=SPFieldText class=ms-formbody vAlign=top width=450>
      <!-- FieldName="ClimateZoneASHRAEIECC"  
          FieldInternalName="ClimateZoneASHRAEIECC" FieldType="SPFieldText" -->&nbsp; 
       </TD>    
    </tr>

    <tr style="display: block;" section-name="Section2">
      <TD class=ms-formlabel vAlign=top width=165 noWrap>
      <H3 class=ms-standardheader>
      <A name=SPBookmark_BaselineEUI></A>BaselineEUI</H3>
     </TD>
      <TD id=SPFieldNumber class=ms-formbody vAlign=top width=450>
      <!-- FieldName="BaselineEUI"  FieldInternalName="BaselineEUI" 
       FieldType="SPFieldNumber" -->&nbsp; 
     </TD>
    </tr>
Was it helpful?

Solution

I'd suggest (given the requirements and hideous, hideous HTML):

// selects those 'td' elements that are the second child (:nth-child(2))
// of their parent 'tr' element with a 'section-name' attribute that is
// equal to 'Section2', and filters that collection:
$("tr[section-name='Section2'] td:nth-child(2)").filter(function(){

    // we retain only those 'td' elements with at least one childNode
    // that is a comment-node (nodeType === 8) and contains the string
    // supplied to 'indexOf()'
    return $(this).contents().filter(function(){
        return this.nodeType === 8 && this.nodeValue.indexOf('FieldInternalName="BaselineEUI"') > -1;
    // if there is a length (IE there was more than zero matching
    // nodes found) we retain the 'td' element we're filtering
    }).length;
// moving to the previous 'td' element, and using 'css()' to color its text red:
}).prev('td').css('color', 'red');

JS Fiddle demo.

References:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top