Home >>jQuery Tutorial >jQuery before() Method
jQuery before() method
Syntax:$(selector).before(content,function(index))
Parameter | Description |
---|---|
content |
It is a Required parameter used to insert the specifies content (can contain HTML tags)
Possible values:
|
function(index) |
It is used to returns the specifies content to insert
|
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$(".txt1").before("<p>Hello Phptpoint!</p>");
});
});
</script>
</head>
<body>
<button class="btn1">click to insert content</button>
<p class="txt1">PHPTPOINT</p>
<p class="txt1">This is a paragraph.</p>
</body>
</html>
PHPTPOINT
This is a paragraph.