2022.2

Table Of Contents
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previousparagraph-thefirst
paragraphintheBox-tobold.
results.prev().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.prev():
var prevSibling = this.prev();
if prevSibling != null { prevSibling.css("font-weight", "bold"); }
remove()
RemovesthecurrentelementoreachelementinasetfromtheDOM.
Thisfunctionreturnsanewresultsetcontainingeachremovedelement.Thesecanbechangedand
insertedinthedocument.Thiscouldbebeneficialintermsofperformance,asmanipulatingelements
insidetheDOMisrelativelytimeconsuming.
Examples
ThisscriptremovesallSpanelementsfoundinthetemplate.
results.remove();
Page 1265