David Bonnici
David Bonnici

Reputation: 6747

jQuery (Append)

For instance I have this html code

<div class="messageContainer">
  <div class="message">
  </div>
</div>

---Here

<div class="messageContainer">
  <div class="message">
  </div>
      <here> :)
</div>

Now I need to create a div with some information located in the text ("---Here"). Is there any way how obviously by using jQuery.

Upvotes: 0

Views: 201

Answers (1)

Jess
Jess

Reputation: 42928

You're looking for the after() command:

$("#messageContainer").after("<div>");

Though in your example, this will add it after every messageContainer. You will need to adjust the selector appropriately. So you'd want #messageContainer:first to add it after only the first container, for example.

before() is also available.

Upvotes: 6

Related Questions