Questions tagged [jquery-after]

A method of jQuery that insert content, specified by the parameter, after each element in the set of matched elements.

The .after() insert content, specified by the parameter, after each element in the set of matched elements.

Using the following HTML:

<div class="container">
  <h2>Greetings</h2>
  <div class="inner">Hello</div>
  <div class="inner">Goodbye</div>
</div>

Content can be created and then inserted after several elements at once:

$( ".inner" ).after( "<p>Test</p>" );

Each inner <div> element gets this new content:

<div class="container">
  <h2>Greetings</h2>
  <div class="inner">Hello</div>
  <p>Test</p>
  <div class="inner">Goodbye</div>
  <p>Test</p>
</div>
40 questions
231
votes
9 answers

.append(), prepend(), .after() and .before()

I am pretty proficient with coding, but now and then I come across code that seems to do basically the same thing. My main question here is, why would you use .append() rather then .after() or vice verses? I have been looking and cannot seem to…
Epik
  • 3,327
  • 4
  • 17
  • 23
57
votes
11 answers

jQuery: What's the difference between after() and insertAfter()

jQuery has an .after() method, and also an .insertAfter() method. What's the difference between them? I think I can use .after() to insert elements after a selected element (or elements). Is that right? What's .insertAfter() for?
Cheeso
  • 189,189
  • 101
  • 473
  • 713
15
votes
2 answers

after() inserting element, then getting it back

Possible Duplicate: Why does jQuery .after() not chain the new element? This reference code: $("#id").after(string); Does a pretty good job inserting the element of the string where its need to. How can I get a reference to newly inserted HTML…
jacktrades
  • 7,224
  • 13
  • 56
  • 83
15
votes
3 answers

Why does jQuery .after() not chain the new element?

I am curious why jQuery's .after() does not chain, or "provide you with," the new element that you create with it. It seems to me like it should, but I am no expert and was hoping someone could shed some light on why it's a bad idea. Here's an…
Bung
  • 259
  • 2
  • 7
13
votes
4 answers

jQuery's after method not working with newly created elements

Insofar as I can tell, the following code should work, creating a
element, and then creating a

element; the expression should result in a jQuery object with two elements: $("

first element's content
").after("

second element's…

Paul Bruno
  • 1,896
  • 1
  • 17
  • 26
7
votes
3 answers

Jquery to fade in .after()?

Simple really but cannot get it to work, here is my script... $('body').after(''); How can I get it to fade in rather than just pop up? putting fadeIn() after or before .after() doesn't…
novactown
  • 129
  • 1
  • 8
7
votes
3 answers

jQuery elements added with after() have incorrect spacing

I have a
    with a number of
  • elements in it. A number of them are hidden and are added to the end of the list upon clicking with jQuery after(). However, for some reason, the elements added with after() are always a bit too close to the…
waffl
  • 5,179
  • 10
  • 73
  • 123
7
votes
5 answers

Curious about hide().after("") in jQuery

I have some code at here: html:

This is a paragraph.

Javascript: $(document).ready(function(){ $("button").click(function(){ $("p").hide().after('

hello world

'); }); }); Actually, I've…
Marslo
  • 2,994
  • 4
  • 26
  • 35
5
votes
2 answers

Using .after() to add html closing and open tags

I'm trying to split an unordered list into two columns by finding the halfway point of the list and adding
    after that . This could be the complete wrong way to do this but it is how I thought to do it. My js looks like…
user1120130
  • 61
  • 1
  • 3
5
votes
3 answers

Jquery: How to combine addCLass() after() and slideDown()

I'm trying to add a Class to an existing div container and insert a new div (on success) below the existing one.