This project is archived and is in readonly mode.

#631 ✓invalid
fcartegnie

Core 1.2.1, getChildren() throws error with IE6/7

Reported by fcartegnie | March 31st, 2009 @ 04:19 AM | in 2.0 (closed)

I'm unable to use getChildren() with IE6/7. works with any other browser. Error thrown is "this object has no such property or method". (translation)

My code looks like that: foo(a) { a.getChildren(); } foo

Works if I lookup the id instead of having the element passed to the function: If I try something like $('foo').getChildren() there's no error.

Comments and changes to this ticket

  • Daniele C.

    Daniele C. March 31st, 2009 @ 12:03 PM

    • Tag changed from 1.2.1, explorer, getchilrent, ie to 1.2.1, explorer, getchildren, ie

    Sorry, but I really was not able to reproduce the error. I've tried to do somethig like this:

    @@@Javascript

    <ul>
        <li>sss</li>
        <li>sss</li>
    </ul>
    <p>
    
    </p>
    
    
    function printElems(a){
        document.write(a.getChildren()+"<br/>");
    }
    
    printElems($('OK'));
    
    
    
    
    But it works with no problem in both IE6 and IE7.
    
    Are you doing something different?
    
  • fcartegnie

    fcartegnie March 31st, 2009 @ 01:31 PM

    Yes, differently. You're accessing the element through $() while I'm getting directly its reference from an event or script call.

    
    
    foo(root) { root.getChildren(); }
    
    <a onClick=\"foo(this);\">foo</a>
    

    I now switched back to something like

    
     for(var i=0; i<(root.childNodes.length); i++)
    

    and it works this way :/

  • fcartegnie

    fcartegnie March 31st, 2009 @ 02:14 PM

    • Assigned user set to “Aaron Newton”

    Okay, figured out the reasons:

    The script result generated a page like this:

    
    <form name="formroot">......</form>
    
    <a onClick=\"foo(document.formroot);\">foo</a>
    

    It was accessing the element by name, the old way. In that case, - root.childNodes (works everywhere) - root.getChildren() (works only outside Trident browsers)

    Now, I also identified another problem with 'by name access' and explorer:

    
    
    <img onclick="foo2(this);">
    
    function foo2(me)
    {
    var root = me.getParent();
    var br = document.createElement("br");
    br.inject(root, 'bottom');
    }
    

    Fails on inject. Same kind of error.

    I guess mootools with IE doesn't add the required methods: - document.foo accessed elements - elements created with document.createElement()

    Fixed the page code by accessing by id with $() and (new Element()).inject()

  • fcartegnie

    fcartegnie March 31st, 2009 @ 02:15 PM

    • Assigned user cleared.
  • Tom Occhino

    Tom Occhino April 2nd, 2009 @ 12:55 PM

    • State changed from “new” to “invalid”

    In order to use mootools methods on elements, the must be extended.

    The reason this works in non-ie browsers is because they support HTMLElement.prototype, and we exploit this fact (of course).

    directly from the docs:

    • In Internet Explorer, the Element is extended the first time $ is called on it, and all the Element Methods become available.
    • Browsers with native HTMLElement support, such as Safari, Firefox, and Opera, apply all the Element Methods to every DOM element automatically.
    • Because MooTools detects if an element needs to be extended or not, this function may be called on the same Element many times with no ill effects.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Pages