2022.2

Table Of Contents
Seealso:"after()"onpage786.
before(content)
Before(content)insertscontentbeforeoneormoreHTMLelementsandcreatesanewresultset.
content
String,HTMLstringorresultsettoinsertaftertheelements.Incaseaplaintextstringisprovided,itis
automaticallywrappedina<span>elementtoavoidorphantextnodestoappearinthe<body>ele-
ment.
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");
Page 757