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,aparentisanelementthatcontainsanotherelement.
Togetanancestorthatmatchesaparticularselector,useclosest()(see"closest()"onpage795).
Togetanelement'ssiblingelement,youcanuse"prev()"onpage809or"next()"onpage802.
Example
AssumethattherearethreeparagraphsinaBoxandthatoneofthoseparagraphsmatchesthe
selectorofthisscript.Theparagraphisstoredintheresultsobject(see"results"onpage844).The
followingscriptretrievestheBox(whichistheparentoftheparagraph)usingresults.parent(),
andthenchangesitsbackgroundcolortored.
results.parent().css('background-color' , 'red');
prepend()
InsertcontentatthebeginningofoneormoreHTMLelements,whichcanbe:
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).
Seealso:"append()"onpage788.
prepend(content)
InsertcontentasthefirstelementtoeachelementinthesetofHTMLelementsthatmatchtheselector
ofthescriptorofanotherqueryinthetemplate(see"query()"onpage742).Appendcreatesanewres-
ultset.
content
HTMLstring,stringorHTMLstringtoinsertafterthematchedelements.Incaseaplaintextstringis
provided,itisautomaticallywrappedina<span>elementtoavoidorphantextnodestoappearinthe
<body>element.
Examples
ThisscriptinsertsaheadingasthefirstelementinanelementthathastheID#box.
Page 805