How to use HTML Prepend Method in JQuery
This article describe about HTML Prepend Method in JQuery.
HTML prepend() method in jQuery
The prepend method add the element in the beginning from the selected position.
This method insert element at the inside of selected element.
The prepend method and prependTo method both are same thing but the syntax will be different.
Syntax
$(selector).prepend(content)
|
Example
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$("button").click(function ()
{
$("p").prepend("<b>Hello world!</b> ");
});
});
</script>
</head>
<body>
<p>This is a JQuery.</p>
<p>This is .Netheaven.</p>
<button>Insert content at the beginning of each p element</button>
</body>
</html>
|
Output1
Output2
Using a Function
We use a function to insert specified content at the beginning of the selected elements.
Syntax
$(selector).prepend(function(index,html))
|
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here