Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:29:03+00:00 2026-06-13T12:29:03+00:00

<body> <div> <p id=test></p> </div> <script> // I’m trying to clone an element var

  • 0
<body>
<div>
    <p id="test"></p>
</div>
<script>
    //  I'm trying to clone an element
    var h1 = document.createElement('h1'); // I create <h1>
    h1.innerHTML('test'); // I put some text between this element <h1>test</h1>
    document.getElementById('test').appendChild(h1); // I add this h1 to <p id="test"><h1>test</h>
    var h1Clone = h1.cloneNode(true); // I use cloneNode to clone h1

    // Here I'll clone the <p> tag and add h1Clone to it
    var paragraph = document.getElementById('test'); // Look for id="test"
    paragraph.appendChild(h1); // Add h1 as <p>'s child
    var paragraphClone = paragraph.cloneNode(true); // Clone <p>
    paragraphClone.appendChild(h1Clone); // Add h1Clone as <p>'s (clone) child.

    paragraph.parentNode.appendChild(paragraphClone); // Finally I add <p>'s clone to <body> tag
</script>
</body>
</html>

Hello, I commented everything so you can understand what I’m trying to do..
Why can’t I make it working?

Here is the final html result that I’m trying to have:

<p id="test"><h1>test</h1></p>
<p id="test"><h1>test</h1></p> <-- clone ->
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:29:04+00:00Added an answer on June 13, 2026 at 12:29 pm

    change h1.innerHTML = 'test'; instead of h1.innerHTML('test')

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<head> <script> function getInfo(o) { var obj=o; document.getElementById('test').innerHTML=obj.name1; document.getElementById('test2').innerHTML=obj.name2; } </script> </head> <body> <input
My code is: <body> <p id=tit></p> <script type=text/javascript> try { document.getElementById('tit').innerHTML = <div>test</div>; }
What's wrong with the below? <html> <body> <div id='test'>28</div> </body> </html> <script> $(document).ready(function (){
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <div> <p id=test></p> </div> <script> var newLink
I made this Greasemonkey script: var maxpi = 250; var p1 = /html/body/div/div[2]/div/div[2]/table[2]/tbody/tr[1]/td[11]; var
I am trying to write some test script for a web application. So I
I'm trying to create a simple ajax load test script that dynamically creates divs,
When we run following script under Firefox ... var d = $(<div class='test'></div>); d.hide();
I make a website with DOM structure like this: <body> <div><canvas id=cv></canvas> <script> ..some
The code is as below: <html> <head> <title>test</title> </head> <body> <div><span>shanghai</span><span class=margin> </span><span>male</span></div> </body>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.