.insertBefore()
methodThe .insertBefore()
method in jQuery is used to insert each matched element before the target (outside).
.insertBefore()
method Syntax.insertBefore(target)
The matched elements will be inserted after target
.
.insertBefore()
method ExampleInsert HTML content before all paragraphs
HTML
<div class="container"> <p>Learn JavaScript</p> <p>Learn jQuery</p> </div>
jQuery
$("<p> Lautturi.com </p>").insertBefore("p");
Result
<div class="container"> <p> Lautturi.com </p> <p>Learn JavaScript</p> <p> Lautturi.com </p> <p>Learn jQuery</p> </div>