728x90
SMALL
#jquery
#after()
.after()
.after() can add new elements after the selected element, or move elements elsewhere.
grammar
.after( content [, content ] )
for example
$( 'h1' ).after( '<p>Hello</p>' );
will add a p element with Hello as content after the h1 element.
$( 'h1.a' ).after( $( 'p.b' ) );
will move p elements with b as class value after h1 elements with a as class value.
example1
After the h1 element, add a p element with Hello World! as its content.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery</title>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$( document ).ready( function() {
$( 'h1' ).after( '<p>Hello World!</p>' );
} );
</script>
</head>
<body>
<h1>Lorem ipsum dolor.</h1>
</body>
</html>
example2
Move the p element before the h1 element to the end of the h1 element.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery</title>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$( document ).ready( function() {
$( 'h1' ).after( $( 'p' ) );
} );
</script>
</head>
<body>
<p>Goodbye World!</p>
<h1>Lorem ipsum dolor.</h1>
</body>
</html>
Adding or moving an element before the selected element is called .before() .
728x90
LIST