Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




HTML METHODS - prepend()


The prepend() method in JQuery is used to insert a content at the beginning of an HTML element.


Example :



<html>
    <head>
    	<title> My First Programme </title>
  	</head>

  	<body>
    	<h1> JQuery </h1>
    	<p>New Code</p>
    	
    	<button> Click to set a new value </button>
    	

      	<script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script>
	  
      	<script>
      
      		$('button').click( function() {
				$('p').prepend("Added new content at the beginning ");
			});
			
            
      	</script>      
   </body>
</html>


Output :




So, in the above code, we have to to add a new content


'Added new content at the beginning '

At the beginning of,


<p>New Code</p>

And make it


Added new content at the beginning New Code

And we have done it using the JQuery statement,


$('button').click( function() {
	$('p').prepend("Added new content at the beginning ");
});

So, on button click, the prepend() function is called,


$('p').prepend("Added new content at the beginning ");

And the content of <p> element,


New Code

Is added with,


Added new content at the beginning

At the beginning, and the new content is printed on the screen,


Added new content at the beginning New Code