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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:58:15+00:00 2026-05-12T21:58:15+00:00

The goal here is to manipulate some DOM nodes before they are inserted into

  • 0

The goal here is to manipulate some DOM nodes before they are inserted into the document, using prototypeJs methods.

Test cases:

<html>
<head>
    <script type="text/javascript" src="prototype.js" ></script>
</head>
<body>
    <script type="text/javascript">
        var elt = document.createElement("DIV");
        elt.id="root";
        elt.innerHTML="<div id='stuff'><span id='junk'></span></div>";

        console.info(elt);

        console.info(Element.down(elt, "#stuff"));
        console.info(Element.select(elt, "#stuff"));

        console.info(elt.down("#stuff"));
        console.info(elt.select("#stuff"));

        Element.extend(elt);

        console.info(elt.down("#stuff"));
        console.info(elt.select("#stuff"));

        document.body.appendChild(elt);

        console.info($("root").down("#stuff"));
        console.info($("root").select("#stuff"));

    </script>
</body>
</html>

In Firefox all 8 tests correctly output either the “stuff” div or a collection containing only the “stuff” div.

In ie (tested in 7/8) I would expect the second two tests only to fail as prototype does not automatically extend the DOM as in ff. However what actually happens is all the tests up to the point the element is inserted fail the two subsequent tests are fine. Once I call Element.extend if would expect the down / select methods to be available.

If this behaviour as expected and if so why?

How would you recommend I do my DOM traversal on nodes which are in memory in a cross browser friendly manner?


So thanks to Kaze no Koe, I’ve narrowed the issue down. It seems that this does work in ie but not for id selectors.

<html>
    <head>
        <script type="text/javascript" src="prototype.js" ></script>
    </head>
    <body>
        <script type="text/javascript">     
            var elt = document.createElement("DIV");
            elt.id="root";
            elt.innerHTML="<div id='stuff' class='junk'></div>";
            elt = $(elt);       

            console.info(elt.down("DIV"));      //fine
            console.info(elt.down(".junk"));    //fine
            console.info(elt.down("#stuff"));   //undefined in ie, fine in ff
        </script>
    </body>
</html>

It’s not a problem for me to use class instead of id, so I can solve my original issue but for completeness sake can anyone explain why id selectors won’t work before insertion in ie only? My guess would be that the ie implementation relies on document.getElementById whilst the ff one doesn’t. Anyone confirm?

  • 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-12T21:58:15+00:00Added an answer on May 12, 2026 at 9:58 pm

    Instead of:

    Element.extend(elt);
    

    Try:

    elt = Element.extend(elt);
    

    or

    elt = $(elt);
    

    As for how to do the traversing before you’ve inserted the node, here’s some random examples that illustrate a few features of Prototype:

    var elt = new Element('div', {
        className: 'someClass'
    });
    
    elt.insert(new Element('ul'));
    
    var listitems = ['one', 'two', 'three'];
    
    listitems.each(function(item){
        var elm = new Element('li');
        elm.innerHTML = item;
        elt.down('ul').insert(elm);
    });
    
    elt.getElementsBySelector('li'); //=> returns all LIs
    
    elt.down('li'); //=> returns first li
    
    elt.down('ul').down('li'); //=> also returns first li
    
    elt.down('ul').down('li', 2); //=> should return the third if I'm not mistaken
    
    // all before inserting it into the document!
    

    Check the brand new API documentation.


    Answering Ollie: my code above can be tested here, as you can see it works under IE 6.

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

Sidebar

Related Questions

I'm mapping a set of attributes to my entity using @CollectionOfElements. The goal here
I have some code here. I recently added this root_id parameter. The goal of
Note: I've only been using Objective-C for a week. Here's my end goal: I
My goal here is to create a very simple template language. At the moment,
So my goal here is to have a single search field in an application
Here's the goal: to replace all standalone ampersands with &amp; but NOT replace those
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
Overall goal: User enters some number in minutes and I change those numbers from
My goal here is to override a method if it isn't found, otherwise use
So to give a little context, my goal here is to produce a binary

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.