2022.2

Table Of Contents
query("#table_2 > tbody > tr").each(function(i) {
this.find('@ItemNumber@').text( record.tables['detail'][i].fields["ItemNumber"]);
this.find('@ItemOrdered@').text( record.tables['detail'][i].fields["ItemOrdered"]);
this.find('@ItemTotal@').text( record.tables['detail'][i].fields["ItemTotal"]);
this.find('@ItemDesc@').text( record.tables['detail'][i].fields["ItemDesc"]);
this.find('@nr@').text(i);
});
Thefollowingscriptclonesandpopulatesaboilerplaterow.Oncecompletedyouwillneedtohidethe
boilerplaterow.
closest()
Thisfunctiongetsthefirstparentelementthatmatchesaselector,bytestingtheelementitselfandtra-
versingupthroughitsancestorsintheDOMtree.(InHTML,aparentisanelementthatcontains
anotherelement.)
Thefunctioncanbeusedfor:
l
Theelementsthatmatchtheselectorofascript(see"results"onpage844).
l
Oneelementthatmatchestheselectorofascriptthatrunsfor"Eachmatchedelement"(see
"this"onpage781and"Settingthescopeofascript"onpage373).
l
Theelementsreturnedbyaqueryinthetemplate(see"query()"onpage742).
Togetachildelementorallchildelements,usechildren()(see"children()"onpage794).
Theclosest()commandisbasedontheclosest()commandfoundinthejQuerylibrary:
https://api.jquery.com/closest/.
Togetanelement'ssiblingelement,youcanuse"prev()"onpage809or"next()"onpage802.
closest(selector)
ForoneHTMLelementorforeachelementinaset,thisfunctiongetsthefirstelementthatmatchesthe
selectorbytestingtheelementitselfandtraversingupthroughitsancestorsintheDOMtree.
selector
AStringcontaininganHTMLtag(withouttheanglebrackets,<>).
Examples
Thefollowingscriptlooksupalltablerowsinthetemplatethatcontainan<input>element.
query("input").closest("tr");
Thiscodegetstheclosest'parent'rowforeachelementthatmatchestheselectorofthescript(col-
lectedintheresultsobject):
Page 760