How to select spans that have a specific attribute in javascript
<p>I'm trying to manipulate spans that have the "email" attribute, this is my code:</p>

<pre><code>var spans = document.getElementsByTagName("span"),
    index, node, emailAttr;
for (index = 0; index &lt; spans.length; ++index) {
    node = spans.item(index);
    emailAttr = node.getAttribute("email");
    if (emailAttr) {
        // Do something with `node` and `emailAttr`
    }
}
</code></pre>

<p>Everything goes well until the last if statement, it can find the spans but no result for spans that have the email attribute. What is wrong here?</p>

<p>This is part of the html code i'm trying to scan:</p>

<pre><code>&lt;span class="yP" email="nobody@mozilla.org"&gt;Mozilla Add-ons&lt;/span&gt;
</code></pre>

<p>Note: i don't want to use jQuery. </p>
