Well, since IE doesn't support the namespaced versions of createElement and setAttribute, you'll need to abstract the process. I use this function for just this sort of thing
Code:
document.createHTMLElement = function( elemName, attribs )
{
if ( document.createElementNS )
{
var elem = document.createElementNS( "http://www.w3.org/1999/xhtml", elemName );
var isNamespaced = true;
}
else
{
var elem = document.createElement( elemName );
var isNamespaced = false;
}
if ( typeof attribs != 'undefined' )
{
for ( var i in attribs )
{
switch ( true )
{
case ( i == 'text' ) : elem.appendChild( document.createTextNode( attribs[i] ) ); break;
case ( i == 'class' ) : elem.className = attribs[i]; break;
default :
if ( isNamespaced )
{
elem.setAttributeNS( "http://www.w3.org/1999/xhtml", i, '' );
}
else
{
elem.setAttribute( i, '' );
}
elem[i] = attribs[i];
}
}
}
return elem;
}
The 2nd argument is an object literal specifying all the attribute/value pairs. Example
Code:
var a = document.createHTMLElement( "a", { title:'Email Tecknetix', class:'hov', href:"mailto:" + mailpart1 + "@" + mailpart2, text: showtext } );
There, in one fail swoop, you create the entire element, namespace it if necessary, and propertly set attributes (Opera likes them to be blank first, then a value set)
[/CODE]
Bookmarks