How to use HTML Before Method in JQuery
This article describe about HTML Before Method in JQuery.
HTML before() method in jQuery
The before() method is used to insert an element on the selection position.
This before() method add the element at the front position of the selected element.
Syntax
$(selector).before(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").before("<p>Hello world!</p>");
});
});
</script>
</head>
<body>
<p>This is a JQuery.</p>
<button>Insert content afer click this button</button>
</body>
</html>
|
Output1
Output2
Using a Function
We use a function to insert specified content before selected elements.
Syntax
$(selector).before(function(index))
|
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