2022.2

Table Of Contents
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):
results.closest("tr");
Therowscouldbecoloredredwithinthesamestatement:
results.closest("tr").css('background-color','red');
css()
GetsthevalueofastylepropertyofoneHTMLelement,orsetsoneormoreCSSpropertiesofoneor
moreHTMLelements.
Page 795