Javascript Ajax jQuery Html PHP Example Quiz New MORE

jQuery before() method With Example

To get or set text content for a selected element in jQuery html() method is used. It is an inbuilt method of jQuery.

Syntax:

$(selector).text(function(index,currentcontent))

Example:

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
    $("button").click(function(){  
        $("p").before("<h1>www.studentstutorial.com</h1>");  
        $("button").hide();
    });  
});  
</script>  
</head>  
<body>  
    <button>Insert content before each p element</button>  
    <p>This is a tutorial website for all technology.</</p>  
 
</body>  
</html>

Run it Yourself »