Welcome to findnerd, today we are going to discuss on prepend() method in jQuery.
Firstly let know what use of prepend() method ?
prepend() method is used for inserting at the beginning of the selected elements in jQuery
you can see bellow example how it works
<!DOCTYPE html>
<html>
<head>
<!-- here call the jquery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("p").prepend("Fine Joe ");// call prepend() to add text
});
});
</script>
</head>
<body>
<!-- here write paragraf in which you want add text-->
<p>What about you ?</p>
<!--define button id -->
<button id="btn">Submit</button>
</body>
</html>
output will be following:
when you will click on submit button then "Fine Joe " will be add in your beginning of paragraph.
Fine Joe What about you ?
0 Comment(s)