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:
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.
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.
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<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>
</head>
<body>
<script type="text/javascript">
document.write( 'Name: ' + BADRABBIT.testStart() );
</script>
</body>
</html>
Thanks again for taking pity on this fool.
Last edited by Dr.Goodvibes; 10-06-2010 at 08:46 AM.
Reason: Coding
Bookmarks