This method is used to insert the data before some specified tag or content . It is able to add the content at specified position by the parameter after matching the elements . insertBefore( ) and before( ) methods are same, they perform same task . There is only syntax difference in both the method . Syntax :
$(selector).before(content,function())
Example :HTML Code :
<html>
<head></head>
<body>
<button>After click ,Data added before p tag</button>
<p>Hello Mukesh Tomar</p>
<p>From Meerut</p>
</body>
</html>
jQuery Code :
$(funtion(){
$("button").click(function(){
$("p").before("<p><b>I have added before p tag</b></p>");
});
});
0 Comment(s)