Help with creating surrounding tag
Hi, I'm trying to create the equivalent code in javascript:
<media><img src="whatever"/></media>
My code is currently like this:
oImage = main.CreateElement( 'IMG' ) ;
/* this then calls this function */
main.CreateElement = function( tag )
{
var loc = main.EditorDocument.createElement( tag );
return main.InsertElementAndGetIt(loc);
}
/* this function is called above */
main.InsertElementAndGetIt = function( e )
{
e.setAttribute( '__TempLabel', 1 ) ;
this.InsertElement( loc ) ;
var aEls = main.EditorDocument.getElementsByTagName( e.tagName ) ;
for ( var i = 0 ; i < aEls.length ; i++ )
{
if ( aEls[i].getAttribute( '__TempLabel' ) )
{
aEls[i].removeAttribute( '__TempLabel' ) ;
return aEls[i] ;
}
}
This creates my <img> tag and I know how to set those specific <img> attributes from there, but I am confused about how to add the surrounding <media> tag. I've returned the location of the tag to oImage as stated in the first line of the code, but I don't know where to go from there. Any help?
Thanks
Ben
|