help on removing element using yui

Discussion in 'Javascript' started by shotokan99, Aug 30, 2007.

  1. shotokan99

    shotokan99 Guest

    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.
     
    shotokan99, Aug 30, 2007
    #1
    1. Advertising

  2. shotokan99

    Guest

    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);




    On Aug 30, 6:08 am, shotokan99 <> wrote:
    > 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.
     
    , Aug 30, 2007
    #2
    1. Advertising

  3. shotokan99

    shotokan99 Guest

    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?
     
    shotokan99, Aug 30, 2007
    #3
  4. On Aug 29, 11:27 pm, shotokan99 <> wrote:
    > 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
     
    David Golightly, Aug 30, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sumit
    Replies:
    2
    Views:
    430
    Dhaivat Pandya
    Feb 22, 2011
  2. YUI Custom Events Problem

    , Jul 13, 2006, in forum: Javascript
    Replies:
    5
    Views:
    124
    Richard Cornford
    Jul 14, 2006
  3. hedgehog
    Replies:
    1
    Views:
    145
    hedgehog
    Apr 6, 2007
  4. [HELP] Learning XML with YUI

    , May 22, 2007, in forum: Javascript
    Replies:
    0
    Views:
    129
  5. shotokan99

    help on yui tree menu

    shotokan99, Aug 29, 2007, in forum: Javascript
    Replies:
    4
    Views:
    113
    shotokan99
    Aug 30, 2007
Loading...

Share This Page