Results 1 to 3 of 3

Thread: Help required - Create nodelist collection.

  1. #1
    Join Date
    Oct 2010

    Question Help required - Create nodelist collection.


    Sorry if I sound like a nob.

    I'm trying to create the following JavaScript object nodelist collection structure.

    There are many examples and ways to read the DOM structure, but I can't find any reference on how to create your own.

    If someone has a pointer to documentation or code example that'd be fantastic.

    I'm reading the rhinoceros book and again can't find an example of this construct, although it is noted in passing throughout the book.

    Thanks in advance for any help, sorry I sound so stupid.

  2. #2
    Join Date
    Dec 2003
    Bucharest, ROMANIA
    I think you confound the terms: to create a node vs. to circle through the child nodes of a parent node.

    To create:
    DOM nodes are of different types (elements, textNodes, attributes, comments, CDATA sections). You can not create a generic node, you can create a specified type of node, and any type of node can be created using a specific method. See also:


    To circle:
    Use a loop, and the childNodes.length as limit

  3. #3
    Join Date
    Oct 2010
    Thank you for your reply,

    What I'm doing is, returning an xhr.responseXML from server side XSLT as a fragment. This is then parsed. Inside the returned fragment is non-HTML code which can be parsed in the same way as any other DOM node/element, but it's used to construct the buttons at the bottom of the pop-up window.

    <badrabbit button="button">
          <popbutton name="submit" value="Submit" onclick="etc">
          <popbutton name="cancel" value="Cancel" onclick="etc">
    This is done so that the server side XSL code and the client side Javascript don't become to inter-dependent, client side presentation only, server side code structure.

    This all works fine and now all I'm doing is placing the button structure into an object to then display at the bottom of the pop-up window appended to the document.

    An example of my old approach but same structure can be seen at concreteresurfacing dot co dot nz and then click on the pictures at the right or the about at the bottom of the page, you will create an XSLT pop-up window.

    The following test snippet of code may help you see where I going wrong and maybe my un-educated approach.

    You're right, I'm confused, I've done tons of work with XSL and used to the DOM building approach.

    For some reason I was looking at attempting to create a JavaScript object.
    Hadn't thought about just using the DOM construct.

    So would it be best to just start from document.createElement( myButton ) and just build a DOM 'fragment'?

    The Javascript (sans DOM) approach would not be an array, but a set of methods that just make it sort of look like one.

    <!DOCTYPE html>
    <html  xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <meta charset="utf-8" />
    <title>Test Object Class</title>
    <script type="text/javascript">
    var BADRABBIT = function() {
        return {
                testLoop: function( obj ){
    	        for ( i = 0; i < 2; i++ ) {
    		    obj.oButt.item(i).name = 'Test' + i;
                    return obj;		  
    	    testInit: function(){
                    this.oButt = new BADRABBIT.button();
    		/*Initilize to verify that name can be overwritten with a new value later on*/
    		this.oButt.item(0).name = 'test9';		  
    		return this;
    	    button: function(){
    		  this.requested = false;
    		  this.length = 0;
    		  /* This where I'm stuck */
    		  /* ???????????????????? */
    		  this.item = function(){}
    		  /*????????????????????? */
                testStart: function(){
                    var obj = BADRABBIT.testInit();
                    obj = BADRABBIT.testLoop( obj );
                    alert( 'Name: ' + obj.oButt.item(1).name );
                    return obj.oButt.item(1).name
    <script type="text/javascript">
    document.write( 'Name: ' + BADRABBIT.testStart() );
    Thanks again for taking pity on this fool.
    Last edited by Dr.Goodvibes; 10-06-2010 at 09:46 AM. Reason: Coding

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center