Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript Elements with class / variable ID
    primarykey
    data
    text
    <p>There's a page with some HTML as follows:</p> <pre><code>&lt;dd id="fc-gtag-VARIABLENAMEONE" class="fc-content-panel fc-friend"&gt; </code></pre> <p>Then further down the page, the code will repeat with, for example:</p> <pre><code>&lt;dd id="fc-gtag-VARIABLENAMETWO" class="fc-content-panel fc-friend"&gt; </code></pre> <p>How do I access these elements using an external script? </p> <p>I can't seem to use document.getElementByID correctly in this instance. Basically, I want to search the whole page using oIE (InternetExplorer.Application Object) created with VBScript and pull through every line (specifically VARIABLENAME(one/two/etc)) that looks like the above two into an array.</p> <p>I've researched the Javascript and through trial and error haven't gotten anywhere with this specific page, mainly because there's no tag name, and the tag ID always changes at the end. Can someone help? :)</p> <p>EDIT: I've attempted to use the Javascript provided as an answer to get results, however nothing seems to happen when applied to my page. I think the tag is ALSO in a tag so it's getting complicated - here's a major part of the code from the webpage I will be scanning.</p> <pre><code>&lt;dd id="fc-gtag-INDIAN701" class="fc-content-panel fc-friend"&gt; &lt;div class="fc-pic"&gt; &lt;img src="http://image.xboxlive.com/global/t.58570942/tile/0/20400" alt="INDIAN701"/&gt; &lt;/div&gt; &lt;div class="fc-stats"&gt; &lt;div class="fc-gtag"&gt; &lt;a class="fc-gtag-link" href='/en-US/MyXbox/Profile?gamertag=INDIAN701'&gt;INDIAN701&lt;/a&gt; &lt;div class="fc-gscore-icon"&gt;3690&lt;/div&gt; &lt;/div&gt; &lt;div class="fc-presence-text"&gt;Last seen 9 hours ago playing Halo 3&lt;/div&gt; &lt;/div&gt; &lt;div class="fc-actions"&gt; &lt;div class="fc-icon-actions"&gt; &lt;div class="fc-block"&gt; &lt;span class="fc-buttonlabel"&gt;Block User&lt;/span&gt; &lt;a href="#" class="fc-blockbutton" onclick="return FriendCenter.BlockFriend('INDIAN701'); return false;"&gt;&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="fc-text-actions"&gt; &lt;div class="fc-action"&gt;&amp;nbsp;&lt;/div&gt; &lt;span class="fc-action"&gt; &lt;a href="/en-US/MyXbox/Profile?gamertag=INDIAN701"&gt;View Profile&lt;/a&gt; &lt;/span&gt; &lt;span class="separator-icon"&gt;|&lt;/span&gt; &lt;span class="fc-action"&gt; &lt;a href="/en-US/GameCenter?compareTo=INDIAN701"&gt;Compare Games&lt;/a&gt; &lt;/span&gt; &lt;span class="separator-icon"&gt;|&lt;/span&gt; &lt;span class="fc-action"&gt; &lt;a href="/en-US/MessageCenter/Compose?gamertag=INDIAN701"&gt;Send Message&lt;/a&gt; &lt;/span&gt; &lt;span class="separator-icon"&gt;|&lt;/span&gt; &lt;span class="fc-action"&gt; &lt;a href="#" onclick="return FriendCenter.AddFriend('INDIAN701');"&gt;Send Friend Request&lt;/a&gt; &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/dd&gt; </code></pre> <p>This then REPEATS, with a different username (the above username is INDIAN701).</p> <p>I tried the following but clicking the button doesn't yield any results:</p> <pre><code>&lt;script language="vbscript"&gt; Sub window_onLoad Set oIE = CreateObject("InternetExplorer.Application") oIE.visible = True oIE.navigate "http://live.xbox.com/en-US/friendcenter/RecentPlayers?Length=12" End Sub &lt;/script&gt; &lt;script type="text/javascript"&gt; var getem = function () { var nodes = oIE.document.getElementsByTagName('dd'), a = []; for (i in nodes) { (nodes[i].id) &amp;&amp; (nodes[i].id.match(/fc\-gtag\-/)) &amp;&amp; (a.push(nodes[i])); } alert(a[0].id); alert(a[1].id); } &lt;/script&gt; &lt;body&gt; &lt;input type="BUTTON" value="Try" onClick="getem()"&gt; &lt;/body&gt; </code></pre> <p>Basically I'm trying to get a list of usernames from the recent players list (I was hoping I wouldn't have to explain this though :) ).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload