2022.2

Table Of Contents
prepend()
InsertcontentatthebeginningofoneormoreHTMLelements,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).
Seealso:"append()"onpage1244.
prepend(content)
InsertcontentasthefirstelementtoeachelementinthesetofHTMLelementsthatmatchtheselector
ofthescriptorofanotherqueryinthetemplate(see"query()"onpage1197).Appendcreatesanew
resultset.
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.
results.prepend("<h1>Personal information</h1>");
Selector Matched element Matched element after script execution
#box <divid="box">
<p>PeterParker</p>
</div>
<divid="box">
<h1>Personalinformation</h1>
<p>PeterParker</p>
</div>
Thisscriptinsertsaheadingasthefirstelementinanelementthathastheclassname.
results.prepend("<b>Name: </b>");
Page 1262