2022.2

Table Of Contents
Matched element Matched element after script execution
<pid="salesrep">PeterParker</p> <p>Loremipsum</p>
<pid="salesrep">PeterParker</p>
ThefollowingscriptlooksforanelementwiththeIDsalesrep,insertsaparagraphbeforethatelement
andcolorsthatelementred.
query("#salesrep").before("<p>Lorem ipsum</p>").css("color","red");
Matched element Matched element after script execution
<pid="salesrep">PeterParker</p> <p>Loremipsum</p>
<pid="salesrep"style="color:red;">PeterParker</p>
Note:thewaythefunctionsbefore()andcss()areusedinthisscriptiscalled'chaining'.Chaining
isoptional;thesamecouldbeachievedbystoringtheresultofthequeryinavariable:
var salesrep = query("#salesrep");
salesrep.before("<p>Lorem ipsum</p>");
salesrep.css("color","red");
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");
Page 1214