Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Suppose you have this HTML :</p> <pre><code>&lt;input name="test" class="cssclassname"&gt; </code></pre> <p>You'd got it with</p> <pre><code>document.getElementsByTagName('input') </code></pre> <p>or</p> <pre><code>document.getElementsByName('test') </code></pre> <p>or</p> <pre><code>document.getElementsByClassName('cssclassname') </code></pre> <p>Also, you can call <code>getElementsByTagName</code> on elements other than document. For example the following is allowed, </p> <pre><code>document.getElementsById('foo').getElementsByTagName('bar') </code></pre> <p>But <code>getElementsByName</code> can only be called on <code>document</code>.</p> <p>Notes :</p> <ul> <li>JavaScript is case sensitive, you can't write the functions like you did in your question</li> <li>those functions don't return just the element but a live <a href="https://developer.mozilla.org/en-US/docs/Web/API/NodeList?redirectlocale=en-US&amp;redirectslug=DOM/NodeList" rel="noreferrer">nodeList</a>, so you'll have to iterate over the result or take the first one if you're sure it's good : <code>document.getElementsByTagName('input')[0]</code></li> <li>the MDN is a good documentation for JavaScript methods. You should read <a href="https://developer.mozilla.org/en-US/docs/Web/API/element.getElementsByTagName?redirectlocale=en-US&amp;redirectslug=DOM/element.getElementsByTagName" rel="noreferrer">getElementsByTagName</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/document.getElementsByName" rel="noreferrer">getElementsByName</a>.</li> </ul>
 

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