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 8553913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:45:45+00:00 2026-06-11T14:45:45+00:00

I have cloned a node, but i want to set or change an attribute

  • 0

I have cloned a node, but i want to set or change an attribute of a div inside that cloned node, specifically, change the id of div id="test0"

I can’t find any documentation out there on this, any straight JavaScript guys out there know a solution?

var c = document.getElementById("stone-opt0"),
cloned = c.cloneNode(true);

//CODE THAT DOESN'T WORK
cloned.getElementById("test0").id = "new-id";

What I am doing is looping through a large list of items, and placing these items into a document fragment, which i then push to the page once… I am doing this rather than adding each element to the page, then modifying after attaching to the DOM (which would be faster, no?)

  • 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-11T14:45:46+00:00Added an answer on June 11, 2026 at 2:45 pm

    You’re trying to call getElementById on the context of an element node. This is not possible: the getElementById method exists only on the document node (because id values have to be unique to the document). By contrast, you can do getElementsByTagName or querySelectorAll based on the context of an element.

    You could, therefore, use the querySelectorAll method to do this, as long as you don’t mind not supporting browsers that don’t support this method, e.g. IE8.

    cloned.querySelectorAll('[id="test0"]')[0].id = "new-id";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cloned the node git repo but the waf build tool that comes with
I have a data object that is deep-cloned using a binary serialization. This data
I have a repo (origin) on a USB key that I cloned on my
I have a site at blog.foobar.com that I have closed down, and I want
Ok, I have an in template function that get's submitted via method=POST. But I
I have two XML docs that I've created and I want to combine these
Suppose I have a partial dom tree with a parent node and a set
I have a div that is being duplicated dynamically. After duping it, I need
I am impressed of Node.js but have small problems trying to imagine how I
I have cloned a remote SVN repository with git-svn. I have modified a pom.xml

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.