PSD to HTML conversion PSD to HTML conversion PSD2HTML.com with over 300 professionals takes the designs to HTML and beyond

Code Snippet

Home » Code Snippets » jQuery » Insert Element Between Other Elements

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

Subscribe to The Thread

  1. Dyllon

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

  2. Dyllon

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

  3. :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('');

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~