jeudi 2 novembre 2017

TreeWalker.nextNode() throws eception in Internet Explorer

I try to traverse nodes in DOM with TreeWalker. In all browsers (including Edge) it is OK, but in Internet Explorer calling the nextNode() method throws an Error. No message is added to this error and the error number is -2147352567 (I did not find this error number anywhere in documentation).

Here is the code sample:

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
function run()
{
    var walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT, {}, false);
    console.log(walker);

    try {
        walker.nextNode();
    } catch (err) {
        console.error(err);
    }
}
        </script>
    </head>
    <body>
        <div>
            <p>some text 1</p>
            <p>some text 2</p>
        </div>
        <input type="button" value="do it" onclick="run()" />
    </body>
</html>

Can anyone help me please?

Thank you.




Aucun commentaire:

Enregistrer un commentaire