jQuery: The Write Less, Do More JavaScript Library

Manipulation/insertAfter

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Manipulation

insertAfter( content )

Insert all of the matched elements after another, specified, set of elements.
This operation is, essentially, the reverse of doing a regular $(A).after(B), in that instead of inserting B after A, you're inserting A after B.
Arguments:
contentString
Content after which the selected element(s) is inserted.

Examples:
Inserts all paragraphs after an element with id of "foo". Same as $("#foo").after("p")

$("p").insertAfter("#foo"); // check after() examples

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="../jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("p").insertAfter("#foo"); // check after() examples
  });
  </script>
  <style>#foo { background:yellow; }</style>
</head>
<body>
  <p> is what I said... </p><div id="foo">FOO!</div>
</body>
</html>

NameType