Grow your CSS skills. Land your dream job.

Last updated on:

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 />");

Comments

  1. Dyllon
    Permalink to comment#

    This will also work..
    $("p:not(:first-of-type)").before("");

  2. Dyllon
    Permalink to comment#

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

  3. Permalink to comment#

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


    $('.parent_of_target_p_tags').children('p.not(:last-child)').after('');

Leave a Comment

Current day month ye@r *

*May or may not contain any actual "CSS" or "Tricks".