2022.2

Table Of Contents
Thefollowingscriptsearchestheresultsforthestring"ipsum"andputs"Lorem"beforeit."Lorem"is
automaticallywrappedinaSpanelement.
results.find("ipsum").before("Lorem ");
Matched element Matched element after script execution
<p>ipsumdolorsitamet,consecteturadipiscingelit.</p> <p><span>Lorem</span>ipsumdolorsitamet,consecteturadipiscingelit.</p>
ThefollowingscriptlooksforanelementwiththeIDsalesrepandinsertsthetext"LoremIpsum"before
thatelement."LoremIpsum"isautomaticallywrappedinaSpanelement.
query("#salesrep").before("Lorem Ipsum");
Matched element Matched element after script execution
<p>ipsumdolorsitamet,consecteturadipiscingelit.</p> <span>LoremIpsum</span>
<pid="salesrep">PeterParker</p>
children()
Returnstheimmediatechildren(innerHTML)ofoneormoreHTMLelements,whichcanbe:
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).
Examples
ThisscriptretrievestheinnerHTMLofanelementselectedfromasnippet.
var snippet = loadhtml('snippets/snippet.html','#foobar').children();
results.append(snippet);
ThefollowingscriptretrievestheinnerHTMLoftheelementsandthenperformsafind/replace.
var snippet = loadhtml('snippets/snippet.html','#foobar').children();
Page 793