In this post, we are going to see jQuery before and insertBefore methods.
Both do the same task, insert text or html before every selected elements but syntax is quite different.
Syntax for after():
$("selectors").before("element to be inserted") ;
Example :
$("div").before("
inserting using after
");
Syntax for insertBefore() :
$("element to be inserted") .insertBefore("div");
Example:
$("
inserting using insertBefore
").insertBefore("div");
Let’s understand with the help of example:
Jquery before and insertBefore example Jquery before and insertBefore example
Hello world from java2blog!!!!Welcome to JQuery.
Live demo: Jquery before and insertBefore example on jsbin.com