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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:17:50+00:00 2026-05-27T09:17:50+00:00

context = document.createElement(span); start_element = my_start_element; end_element = my_end_element; // some how iterate through

  • 0
context = document.createElement("span");
start_element = my_start_element;
end_element = my_end_element;

// some how iterate through here (assuming start and end are different elements)
[start_element .. end_element].each(function(current_element){
   context.append(current_element);
});

pretty straight forward, just don’t know how to do the loop part with the start and end nodes. =\

  • 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-05-27T09:17:51+00:00Added an answer on May 27, 2026 at 9:17 am

    You can also accomplish this with the plain DOM and DocumentFragment.

    Assuming that the start and end nodes are siblings and you have the following html:

    <html>
    <head>
        <title></title>
    </head>
    <body>
    <div>
        <p>paragraph 1</p>
        <p id="start">paragraph 2</p>
        <p>paragraph 3</p>
        <ul id="end">
            <li>paragraph 4</li>
        </ul>
        <p>paragraph 5</p>
    </div>
    </body>
    </html>
    

    The following JS will copy the nodes and insert them in another place.

    var start = document.getElementById('start');
    var end = document.getElementById('end');
    
    var newcontainer = document.createElement('div');
    newcontainer.style.backgroundColor = 'red';
    
    var clonednodes = document.createDocumentFragment();
    
    var node = start, lastnode = null;
    while (lastnode!=end){
        // note that cloneNode(true) will lead to duplicate id attributes
        clonednodes.appendChild(node.cloneNode(true));
        lastnode = node;
        node = lastnode.nextSibling;
    }
    
    newcontainer.appendChild(clonednodes);
    
    document.body.appendChild(newcontainer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function sc_HTMLParser(aHTMLString){ var parseDOM = content.document.createElement('div'); parseDOM.appendChild(Components.classes['@mozilla.org/feed-unescapehtml;1'] .getService(Components.interfaces.nsIScriptableUnescapeHTML) .parseFragment(aHTMLString, false, null, parseDOM)); return parseDOM;
I have the following: $(document).ready(function() { var myIframe = document.getElementById('myIframe'); var element = myIframe.contentDocument.createElement('script');
I am adding several entities to an object context. try { forach (var document
I'm creating a HTML Canvas object using this javascript code: var Canvas = document.createElement(canvas);
dv = document.createElement('div'); // create dynamically div tag dv.setAttribute('id', lyr1); // give id to
Situation: A custom Master Document content type inherits from Document The Master Document content
$(document).ready(function() { $('#content').html(''); $.ajax({ url:'data.json', dataType: json, success: function(data) { $('#content').append('<p>'+data.rank+'</p>'); } });}); In
$(document).ready(function(){ contM = $('#main-content'); contS = $('#second-content'); $(contM).hide(); $(contS).hide(); function loadURL(url) { console.log(loadURL: +
document.getelementbyid('txtbox') is not working when I used in content page as it is working
//deep linking $(document).ready(function(){ contM = $('#main-content'); contS = $('#second-content'); $(contM).hide(); $(contM).addClass('hidden'); $(contS).hide(); $(contS).addClass('hidden'); function

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.