• Home
  • About
  • Services
    • Technical SEO
    • Local SEO Services
  • Plugins & Scripts
  • Insights Hub
    • New Posts
    • Technical SEO
    • General Discussion
    • View All Forums
  • Blog
  • Contact
    • Hub
      New posts Search forums
    • What's new
      New posts New profile posts Latest activity
    • Members
      Current visitors New profile posts Search profile posts
    Log in Register
    What's new Search

    Search

    By:
    Advanced search…
    • New posts
    • Search forums
    Menu
    Log in

    Register

    Install the app
    • Home
      • Hub
      • Technical SEO
      You are using an out of date browser. It may not display this or other websites correctly.
      You should upgrade or use an alternative browser.

      Inject Paragraphs <p> after H1 Heading tag with JavaScript

      • Thread starter Chris
      • Start date Sep 12, 2021
      • Sep 12, 2021
      Code:
      <script>
      // JS script to dynamically inject 3 paragraphs after the H1 heading tag.
        (function() {
          // Create the new P element variables
          var para0 = document.createElement('p');
          var para1 = document.createElement('p');
          var para2 = document.createElement('p');
          
          // Add the text content
          para0.innerText = "This is the contents of the first paragraph. This is the contents of the first paragraph.";
      
          para1.innerText = "This is the contents of the second paragraph. This is the contents of the second paragraph.";
      
          para2.innerText = "This is the contents of the third paragraph. This is the contents of the third paragraph.";
          
          // Create the variable to inject after H1 element
          var title = document.querySelector('h1');
          
          // Inject the new P elements after the H1 element
          if (title) {
            title.parentElement.insertBefore(para0, title.nextSibling); }
          
          if (title) {
            title.parentElement.insertBefore(para1, title.nextSibling.nextSibling); }
          
          if (title) {
            title.parentElement.insertBefore(para2, title.nextSibling.nextSibling.nextSibling); }
      
        }) ();
      </script>
       
      Click to expand...
      C
      Written by

      Chris

      Administrator
      Staff member
      • Messages
        55
      • Reaction score
        0
      • Points
        6
      You must log in or register to reply here.
      Share:
      Facebook Twitter Reddit Pinterest Tumblr WhatsApp Email Share Link

      New Posts

      • H
        4 Things to Do Color Correction Service
        • Started by hmkhairul136
        • Sunday at 11:49 AM
        • Replies: 0
        General Discussion
      • C
        Run Screaming Frog in the Cloud on Windows Server
        • Started by Chris
        • Friday at 5:00 PM
        • Replies: 0
        Technical SEO
      • C
        Nofollow Link Highlighter - Free Chrome Browser Extension
        • Started by Chris
        • Jun 15, 2022
        • Replies: 0
        Blog
      • C
        Hide The Ads Google Chrome Extension
        • Started by Chris
        • May 26, 2022
        • Replies: 0
        Blog
      • C
        Hide People Also Asked (PAA) Google Chrome Extension
        • Started by Chris
        • May 24, 2022
        • Replies: 0
        Blog
      • C
        Dropped .UK Domains 11th April 2022
        • Started by Chris
        • Apr 11, 2022
        • Replies: 0
        General Discussion
      • C
        Google Sheets Regex for excluding subfolders
        • Started by Chris
        • Oct 12, 2021
        • Replies: 0
        Technical SEO
      • C
        Modify or Deploy Meta Viewport - Google Tag Manager
        • Started by Chris
        • Sep 24, 2021
        • Replies: 0
        Technical SEO
      • Hub
      • Technical SEO

    Join the Community

    Chris Lever is a freelance SEO Consultant availible for Hire. Join the growing SEO Community Forum to learn new skills.

    Join Us

    Need Help?

    • BB Code
    • Cookie Policy
    • Terms of Use
    • Privacy Policy
    • HTML Sitemap

    Learn More

    • About
    • Availability
    • Popular Posts
    • Projects & Scripts
    • Contact

    Get in Touch

    Chris Lever, Manchester, United Kingdom
    info@chrisleverseo.com
    +44 0161 883 2249

    © 2022 Chris Lever SEO. All rights reserved. Powered by Xenforo

    • This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
      By continuing to use this site, you are consenting to our use of cookies.
      Accept Learn more…