views:

48

answers:

2

Hi guys, 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

+3  A: 

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

rslite
+2  A: 

I would not use querySelectorAll(). Try standard DOM walking like document.getElementById.

Also sounds like it could be the array, maybe something like coin[0]. In Safari with Web Inspector you can dump the entire array to see its contents and where it is in the array if it is a global variable.

http://ejohn.org/blog/thoughts-on-queryselectorall/

Tom