Javascript – DOM Navigation problem,

greasemonkeyjavascriptjquery

please help me select c.. Here's the HTML code:

<div id="a">
    <div id="b"></div>
    <div id="app7019261521_the_coin_9996544" style="left: 176px; top: 448px;">
        <a href="d.com" onclick="(new Image()).src = &#039;/ajax/ct.php?d_id=;action_type=d;post_form_id=6b; return true;"></a>
    </div>
</div>

And here's my Javascript code:

       var coin = document.querySelectorAll("a > [id^=app7019261521_the_coin]");
        if (coin.length == 1) {
            alert(coin.id);
        } else if (coin.length == 0) {
            window.location.reload();
        }

I dont know the problem, coin.length returns 1. But coin.id always return undefined where it should return app7019261521_the_coin_9996544

Maybe it is in the DOM navigation. I don't know. Please help me

Best Answer

It looks like coin is an array of length 1, so you should use coin[0].id