2022.2

Table Of Contents
ThisfunctioncanonlybeusedinaPostPaginationScript;see"PostPaginationScriptAPI"on
page1297.
Foranexamplesee:"CreatingaTableOfContents"onpage852.
next()
next()returnsthenextsiblingofanHTMLelement,whichcanbe:
l
Theelementsthatmatchtheselectorofascript(see"results"onpage1301).
l
Oneelementthatmatchestheselectorofascriptthatrunsfor"Eachmatchedelement"(see
"this"onpage1237and"Settingthescopeofascript"onpage813).
l
Theelementsreturnedbyaqueryinthetemplate(see"query()"onpage1197).
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()"onpage1264).
Whatiftherearenosiblings?
Ifyoucallprev()ornext()onacollectionofelements(either"results"onpage1301ortheresult
setof"query()"onpage1197),thefunctionwillreturnacollectionofsiblings.Ifnoneoftheelements
hasapreviousornextsibling,thecollectionwillbeempty.Actionsperformedonanemptycollection
willsimplyhavenoeffect.
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1301).Thefollowingscriptchangesthefont-weightofthenextparagraph-thethirdpara-
graphintheBox-tobold.
results.next().css("font-weight", "bold");
Iftheelementsinresultsdon'thavesiblings,thislineofcodewillhavenoeffect.Italsowon'tresultin
anerror.
Page 1225