2022.2

Table Of Contents
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).
InHTML,siblingsareHTMLelementsthatsharethesameparent,i.e.HTMLelementsinthesamecon-
tainerelement.
Notethatasiblingcanbeadifferenttypeofelement.Forexample,ifaparagraph,animageandatable
followeachotherinthesameBox,theyaresiblings.
Tip: Togettheprevioussibling,useprevious()(see"prev()"onpage809).
Whatiftherearenosiblings?
Ifyoucallprev()ornext()onacollectionofelements(either"results"onpage844ortheresultset
of"query()"onpage742),thefunctionwillreturnacollectionofsiblings.Ifnoneoftheelementshasa
previousornextsibling,thecollectionwillbeempty.Actionsperformedonanemptycollectionwill
simplyhavenoeffect.
Ifyoucallprev()ornext()onasingleelement(thisinan'Eachmatchedelement'script),andthe
elementhasnopreviousornextsibling,thefunctionreturnsnull.Performinganoperationonanull
valuewillresultinanerror,whichmeansthattherestofthescriptwon'tbeexecuted.Inthiscase,itis
usefultocheckthereturnvalue,unlessit'scertainthatitwillneverbenull.
Example
AssumethattherearethreeconsecutiveparagraphsinaBoxandthatthesecondofthoseparagraphs
hasanIDthatmatchestheselectorofthisscript.Theparagraphisstoredintheresultsobject(see"res-
ults"onpage844).Thefollowingscriptchangesthefont-weightofthenextparagraph-thethirdpara-
graphintheBox-tobold.
results.next().css("font-weight", "bold");
Iftheelementsinresultsdon'thavesiblings,thislineofcodewillhavenoeffect.Italsowon'tresultin
anerror.
Inan'Eachmatchedelement'scriptyouwouldfirstneedtocheckthereturnvalueofthis.next():
var nextSibling = this.next();
if nextSibling != null { nextSibling.css("font-weight", "bold"); }
Page 802