getElementByClassName

by podlipensky

HTML

<table>
    <tbody><tr>
    <td class="votecell">
        

<div class="vote">
    <input type="hidden" value="8656106">
    <a class="vote-up-off" title="This question shows research effort; it is useful and clear (click again to undo)">up vote</a>
    <span class="vote-count-post" title="View upvote and downvote totals" style="cursor: pointer; ">13</span>
    <a class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful (click again to undo)">down vote</a>
    <a class="star-off" href="#" title="This is a favorite question (click again to undo)">favorite</a>
    <div class="favoritecount"><b>7</b></div>   
 
</div>

    </td>
<td class="postcell">
<div>          
    <div class="post-text" itemprop="description">
        <p>When comparing <a href="http://jsperf.com/bind-vs-emulate">this benchmark</a> with chrome 16 vs opera 11.6 we find that</p>

<ul>
<li>in chrome native bind is almost 5 times slower then an emulated version of bind</li>
<li>in opera native bind is almost 4 times faster then an emulated version of bind</li>
</ul>

<p>Where an emulated version of bind in this case is</p>

<pre class="default prettyprint"><code><span class="kwd">var</span><span class="pln"> emulatebind </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">function</span><span class="pln"> </span><span class="pun">(</span><span class="pln">f</span><span class="pun">,</span><span class="pln"> context</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">function</span><span class="pln"> </span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; f</span><span class="pun">.</span><span class="pln">apply</span><span class="pun">(</span><span class="pln">context</span><span...

JavaScript

function getElementByClassName(cls) {
    var doc = document,
        all = doc.all, i, len, elCls, el, result = [];
    function getCls(el){
        return el.className;
    }
    
    for(i = 0, len = all.length; i < len; i++){
        el = all[i];
        elCls = getCls(el);
        if((' ' + elCls).indexOf(' ' + cls) != -1){
            result.push(el);
        }
    }
    return result;
}
console.log(getElementByClassName('post-signature'));//???