Мне нужно проверить, является ли вторая ячейка любых строк с атрибутом section-name = section2
и вторая ячейка, содержащая " FieldInternalName="BaseLineEUI
"в узле комментариев, пустая или нет? Я просто сдался после этого:
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" -->
</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" -->
</TD>
</tr>
Я бы предложил (учитывая требования и отвратительный, отвратительный 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');
Рекомендации:
Node.nodeType
.Node.nodeValue
.String.indexOf()
.
<!-- -->
как это? и кстати, у вас очень странное требование ..