Insert Element Between Other Elements

Last updated on:

For example, if you have five paragraphs in a row and you need to insert a break tag in between all of them. You can't put it before all five (you don't need one at the top) or after all five (you don't need one at the bottom), you only need four.

$("p:not(:last-of-type)").after("<br />");


  1. Dyllon
    Permalink to comment#

    This will also work..

  2. Dyllon
    Permalink to comment#

    there’s supposed to be a break tag between those quotes.

  3. Jesse
    Permalink to comment#

    :first-of-type is not a selector filter so the sinppent doesn’t work.
    Here is the correction


Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed