2022.2

Table Of Contents
Inan'Eachmatchedelement'scriptyouwouldfirstneedtocheckthereturnvalueofthis.prev():
var prevSibling = this.prev();
if prevSibling != null { prevSibling.css("font-weight", "bold"); }
remove()
RemovesthecurrentelementoreachelementinasetfromtheDOM.
Thisfunctionreturnsanewresultsetcontainingeachremovedelement.Thesecanbechangedand
insertedinthedocument.Thiscouldbebeneficialintermsofperformance,asmanipulatingelements
insidetheDOMisrelativelytimeconsuming.
Examples
ThisscriptremovesallSpanelementsfoundinthetemplate.
results.remove();
Selector Paragraph
before script
execution
Paragraph after
script execution
span <p>Loremipsum<span>-
dolorsit</span>amet,con-
sectetueradipiscingelit.</p>
<p>Loremipsumamet,consectetuer
adipiscingelit.</p>
Theselectorofthefollowingsamplescriptistbody.Beforethisscriptruns,thetablebodyconsistsofa
singleplaceholderrowwiththreecells.Afterrunningthescript,itcontainsthirtyrows.Toimproveper-
formance,mostoftheDOMmanipulationtakesplaceondetachedelements.
// Detach the placeholder row from the DOM
var row = query("tr", results).remove();
// Modify the cells of this row
var cells = row.children();
cells[0].html("some text").css("background-color", "yellow");
cells[1].html("some text").css("font-weight", "bold");
cells[2].html("some text");
// Create a number of copies
var rows = row.clone();
for (var i = 0; i < 30; i++) {
rows = rows.add(row.clone());
}
// Attach all copies to the DOM as children of tbody
results.append(rows);
Page 1232