2022.2

Table Of Contents
Examples
ThisscriptlooksforanelementwiththeIDsalesrepandinsertsaparagraphbeforethatelement.
results.before("<p>Lorem Ipsum</p>");
Selector Matched element Matched element after script execution
#salesrep <pid="salesrep">PeterParker</p> <p>Loremipsum</p>
<pid="salesrep">PeterParker</p>
Thisscriptdoesthesame,butitusesthequery()functiontolookuptheelement.
query("#salesrep").before("<p>Lorem ipsum</p>");
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");
Page 792