removeChild error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tader
    New Member
    • Sep 2007
    • 43

    removeChild error

    Hi,
    so i got script like that

    [CODE=javascript]
    var div_box = document.create Element("div");
    div_box.setAttr ibute("id", "music_box" );
    div_box.style.t op = (Number(cords[1]) - 10) + "px";
    div_box.style.l eft = (Number(cords[0]) - 10) + "px";
    document.body.a ppendChild(div_ box);

    var mb_element = document.create Element("div");
    mb_element.setA ttribute("id", "mb_element ");
    mb_element.inne rHTML = "Test";
    $.id("music_box ").appendChild( mb_element);

    $.addEventListe ner($.id("music _box"), "mouseout", function() {
    document.body.r emoveChild($.id ("music_box" ));
    });
    [/CODE]

    and when mouseout i got this error on mozilla firebug

    Code:
    [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLBodyElement.removeChild]" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: http://msounds.lietuvoje.com/main_js.js :: anonymous :: line 365" data: no]
    [Break on this error] document.body.removeChild($.id("music_box"));
    what is wrong????
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    I do not think the "$." is legal syntax in JavaScript. Also the removeChild() function is supposed to have the element to be removed passed to it, not the element's ID attribute. call should look like this.

    Code:
        document.body.removeChild(div_box);

    Comment

    • tader
      New Member
      • Sep 2007
      • 43

      #3
      well it does remove box when i use
      [CODE=javascript]document.body.r emoveChild(div_ box); [/CODE]
      but then i get error like this
      Code:
      Node was not found" code: "8
      [Break on this error] document.body.removeChild(div_box);

      Comment

      • pronerd
        Recognized Expert Contributor
        • Nov 2006
        • 392

        #4
        Originally posted by tader
        but then i get error like this
        Code:
        Node was not found" code: "8
        [Break on this error] document.body.removeChild(div_box);
        Are you calling that line more than once? If so that is likely the problem. Once an element has been removed it can not be removed again. Also are you still using "$." in your code?

        Comment

        • tader
          New Member
          • Sep 2007
          • 43

          #5
          o ok i understand the problem ty for your help

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            I'm not sure about $., but $() is definitely legal if you're using Prototype. You can grab one element or a number of elements using the $ function.

            Comment

            Working...