Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming the <code>video-quality</code> <code>div</code> will only ever have <strong>one</strong> anchor in it, you're not far off:</p> <pre><code>var vid_id=document.getElementById('video-quality'); var anchor=vid_id.getElementsByTagName('a'); anchor[0].innerHTML="High Quality"; // ^^^-- change here </code></pre> <p><em>(There's a shorter way if you don't need to support IE7 and earlier, see <a href="https://stackoverflow.com/a/13280239/157247">David's answer</a> for more.)</em></p> <p>The key was in the name <code>getElementsByTagName</code> (note the plural). It returns a <a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-536297177" rel="nofollow noreferrer"><code>NodeList</code></a>, not an element. A <code>NodeList</code> is (shockingly!) a list of matching nodes, in this case matching <em>elements</em>. <code>innerHTML</code> is a property of individual elements, so we have to index into the <code>NodeList</code> to access a specific element. The code above assumes there is at least one matching element, and updates its HTML. If you want to be more defensive:</p> <pre><code>var vid_id=document.getElementById('video-quality'); var anchors=vid_id.getElementsByTagName('a'); if (anchors[0]) { anchors[0].innerHTML="High Quality"; } </code></pre> <p>That allows for the possibility there are no matching anchors.</p> <p>Note that by doing this, you're removing the <code>span</code> element, since the <code>span</code> is a descendant of the anchor. If you wanted to avoid that, just look for <code>span</code> elements as descendants of the anchor, exactly as you've looked for anchors in the <code>div</code>.</p> <hr> <p>FWIW, I'd recommend using a reasonable JavaScript browser-focussed library like <a href="http://jquery.com" rel="nofollow noreferrer">jQuery</a>, <a href="http://developer.yahoo.com/yui/" rel="nofollow noreferrer">YUI</a>, <a href="http://code.google.com/closure/library" rel="nofollow noreferrer">Closure</a>, or <a href="http://en.wikipedia.org/wiki/List_of_JavaScript_libraries" rel="nofollow noreferrer">any of several others</a>. They provide a <em>lot</em> of utility functionality, and smooth over some browser differences. But if you prefer using the DOM directly, that's fine too.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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