Insert Element Between Other Elements

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. User Avatar
    Permalink to comment#

    This will also work..

  2. User Avatar
    Permalink to comment#

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

  3. User Avatar
    Permalink to comment#

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


    • User Avatar
      Permalink to comment#

      According to my CSS Pocket Reference book, “:first-of-type” is indeed a selector filter.

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.