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

  • Home
  • SEARCH
  • 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 9003807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:45:29+00:00 2026-06-16T00:45:29+00:00

I am using getElementById when I need to clone the div element. Code: printHTML(

  • 0

I am using getElementById when I need to clone the div element.

Code:

printHTML( document.getElementById("div_name").cloneNode(true));

Now I need to use getElementsByClassName

CloneNode is not working when using getElementsByClassName.
How can I put class name in here?

Thank’s

EDIT:

When I try to use this:

printHTML( $('.dataTables_scroll').clone(true) );

You can see my function:

function printHTML(clonedDive){
        var iframe = document.createElement("iframe");
        document.body.appendChild(iframe);
        iframe.contentWindow.onunload = function(){
        $(".DTTT_container").show("fast");
        $("#header_outer").show("fast");
        $(".ColVis.TableTools").show("fast");
        $("#footer").show("fast");
     };
      iframe.contentWindow.document.body.appendChild(clonedDive);
      iframe.contentWindow.print();

      document.body.removeChild(iframe); 
}

I am getting an error in this line:

iframe.contentWindow.document.body.appendChild(clonedDive);

This is an error description:

Uncaught Error: NOT_FOUND_ERR: DOM Exception 8 
  • 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-16T00:45:30+00:00Added an answer on June 16, 2026 at 12:45 am

    getElementsByClassName gets a nodelist, or an array-like object containing elements if you will, as there can be more than one element with the same class.

    getElementsByClassName does this even if only one element matches the class.
    You can generally recognize methods like that be the s in getElements, which means it gets multiple elements, i.e. a nodeList.

    getElementById only gets one element as ID’s are unique.

    To get the first element in the nodelist, use bracket notation, like so:

    document.getElementsByClassName("div_name")[0].cloneNode(true);
    

    or one could use querySelector, which gets the first matching element only

    document.querySelector(".div_name").cloneNode(true);
    

    The jQuery solution would be:

    $('.div_name').clone(true);
    

    and to iterate over elements with a certain classname you’d use a loop

    var elems = document.getElementsByClassName("div_name");
    
    for ( var i=0; i<elems.length; i++ ) {
        printHTML( elems[i].cloneNode(true) );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this code var html='<div class=somediv></div>'; var target=document.getElementById('contentArea'); target.appendChild(html); I'm getting Uncaught Error: NOT_FOUND_ERR:
I need the full height of a div, I'm currently using document.getElementById('measureTool').offsetHeight offsetHeight -
I am trying to access the DIV with the id codeDef using document.getElementById['codeDef'] But
I'm trying to set the focus on a text input element using document.getElementById( 'id'
I am using the following code function xhi(aax) { var aby=document.getElementById(aax); aby.style.bottom=(parseInt(aby.style.bottom)+(screen.height-42)/10)+'px'; if(parseInt(aby.style.bottom)<(screen.height-42))setTimeout('xhi('+aax+')',25); }
<Select> <option value=1>One</option> <option value=2>Two</option> <option value=3>Three</option> </Select> I am using document.getElementById(Example).value; to get
In PHP I'm using DOMDocument and I need to search for an element that
I need some help with drawing a vml line-element using Javascript into a vml
I created a business generator here: http://minespress.net/web_apps/business-cards/ I created a preview pane using document.getElementById(…).className
I need help collapsing a collapsible div on page load. I'm using this JavaScript

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.