help on removing element using yui

S

shotokan99

just a basic question. i added an element on my page using javascript,
that goes like this:

var r=document.getElementById('d_main');
var k=document.createElement('object');
k.setAttribute('id','mplayer');
k.setAttribute('width','320');
k.setAttribute('height','286');
k.setAttribute('classid','CLSID:22D6f312-
B0F6-11D0-94AB-0080C74C7E95');
k.setAttribute('standby','Loading Windows Media Player
components...');
k.setAttribute('type','application/x-oleobject');
k.setAttribute('codebase','http://activex.microsoft.com/activex/
controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112');
k.innerHTML='<param name="Showcontrols" value="True"><embed src="../
movie/Madagascar.avi" width=320 height=240 type="application/x-
mplayer2" name="MediaPlayer"></embed>';
r.appendChild(k);

actually its a windows media player ;-) now is it possible to remove
the element using yui method such as purgeElement() , etc? if so, can
someone pls give me a code snippet on how to do it.

tnx.
 
M

michael

Hi Shotokan,


If you want to remove the element you just added. Then you need to
find te object. and get its parent.

var obj =document.getElementById('mplayer');
obj.parentNode.removeChild(obj);
 
S

shotokan99

i want to do it using yui. so i did it this way:

function gohide(){
var j= new YAHOO.util.Element('d_main');
var q= new YAHOO.util.Element('mplayer');
j.removeChild(q);
}

working! but is this the right way of removing an element using yui?
 
D

David Golightly

i want to do it using yui. so i did it this way:

function gohide(){
var j= new YAHOO.util.Element('d_main');
var q= new YAHOO.util.Element('mplayer');
j.removeChild(q);

}

working! but is this the right way of removing an element using yui?

You don't need or really even *want* to use YUI to remove an element.
YUI's modus operandi as a library is to smooth over browser
differences. Under the covers, it's still using the native browser
DOM, which you should understand BEFORE you begin using YUI. All
modern browsers support basic DOM operations like the "parentNode"
attribute and the "removeChild" method. There's no reason to make
life more complicated than it needs to be. Use DOM, not YUI, for
this. Mich's example will work just fine for your purposes.

-David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top