PDA

View Full Version : JS: createElementNS() function


marijntje@orange.nl
12-21-2006, 12:48 PM
Hello again,

Today some JS troubleshooting. Currently i'm working on a function for creating new xml nodes for my xhtml files which in some occasions (i.e. when the browser supports it) are served as application xml/xhtml. Therfore i'm bound to use teh createElementNS() function. Unfortunately when i run the following code...:

var GLOBAL = {

//private properties

_ns: "",

//public properties

baseURL: "",

//private methods

_getNS: function(){
if(document.getElementById){
this._ns = document.getElementsByTagName("html")[0].getAttribute("xmlns");
return;
}else{
return false;
}
},

_getBaseURL: function(){
if(document.getElementById){
this.baseURL = document.getElementsByTagName("base")[0].getAttribute("href");
}else{
//add method for non compatible browsers
}
},

//public methods

createNode: function(nn, att, el){
if(document.getElementById){
if(!this._ns){
this._getNS();
}
var _b = document.getElementsByTagName(el)[0];
var _e = document.createElementNS(this._ns,nn);
for(var i in att){
_e.setAttribute(i, att[i]);
}
_b.appendChild(_e);
}
}

};

... i receive the following error:
_b has no properties

Probably i'm just blind, but i've been googling all night and still can't find an answer...

Thanx in advance

Marijn