Home  >  jQuery

Example of .before() in jQuery

February 26, 2013
.before() in jQuery adds the value before the calling elementís value. It inserts HTML code at run time before the calling element. We call it as
$("p").before("<p>Hello</p>")
 
Here p is paragraph HTML element. The value is being inserted by calling .before(). Find the example below.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p> World!</p>
<script>$("p").before("<p>Hello</p>");</script>
</body>
</html>
 
Output

Hello

World!

FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us