AJAX: htmlfile: member not found

 I got the above error when I was trying to assign a string like:

"color:Red;background-color:blue";

directly to the style property of an element, as such:

var td = document.createElement("td");
td.style = this._style; //style holds the string above

This caused the error that was something like htmlfile: member not found.  This is because style is an object, and that doesn't work quite that way.  I found this that has some more information on the subject:  http://www.howtocreate.co.uk/tutorials/javascript/dombasics.  Switching to:

var td = document.createElement("td");
td.setAttribute("style", this._style);

Works in FireFox and not IE 7.  So the issue warrants additional investigation, but at least I'm a step further than I was before.  As a side note, I also used the additional setup of using the cssText property, and checking for the type being a string,  The cssText property is supported, but some browsers don't allow the value to be written to, and the value isn't always a string in some browsers.  So by checking that the type of the property is a string first before assigning, this ensures a different exception isnt' thrown.

But that didn't work for me in IE 7 as well, while working in FireFox.  If anyone has a better solution, please comment on this post.

 

Comments

No Comments