title: getElementsByClassName is not a function in Firefox
body: <p>My to-read shelf on GoodReads is a mix of published and unpublished books making it hard to find something published to read. I figured I could throw together a GreaseMonkey script that would change the background of the entry for the books that haven't yet been published. </p>
  
  <p>This is what I have put together so far:</p>
  
  <pre><code>// ==UserScript==
  // @name        Unpublished Lowlighter
  // @description Makes the background of books not yet published on the Goodreads to-read shelf grey.
  // @include     http://www.goodreads.com/*
  // ==/UserScript==
  
  function dateColor() {
      var books = document.getElementsByClassName('bookalike review');
      for (var book in books) {
          var dateString = book
                          .getElementsByClassName('field date_pub')
                          .getElementsByClassName('value')
                          .textContent;
          var date = new Date(dateString);
          var today = new Date();
          if (date &gt; today) {
              book.style.backgroundColor('Lightgrey');
          }
      }
  }
  
  dateColor();
  </code></pre>
  
  <p>The problem is that it doesn't work. When I tried running the script in scratchpad it gives me the error: <code>Exception: book.getElementsByClassName is not a function</code></p>
  
  <p>I was under the impression that Firefox supports <code>getElementsByClassName</code> and that you can run it on the result of <code>getElementsByClassName</code> to get the child elements. Where am I going wrong?</p>
  
  <p>EDIT: Here is a snippet of the HTML for one <code>&lt;tr&gt;</code> in the table. The reason that I didn't post this to begin with is that it is really verbose: </p>
  
  <pre><code>&lt;tr id="review_265364012" class="bookalike review"&gt;
    &lt;td class="field checkbox" style="display: none"&gt;&lt;label&gt;checkbox&lt;/label&gt;&lt;div class="value"&gt;      &lt;input id="checkbox_review_265364012" name="reviews[265364012]" value="265364012" type="checkbox"&gt;
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field position"&gt;&lt;label&gt;position&lt;/label&gt;&lt;div class="value"&gt;        &lt;div class="reorderControls"&gt;
              &lt;a class="actionLink" href="#" id="loading_link_434018960" method="post" onclick="$(this).hide(); $('loading_anim_434018960').show(); $('hidden_link_434018960').simulate('click');; return false;"&gt;&lt;img alt="up" src="http://www.goodreads.com/assets/up_arrow-7957f2bae9c3456ec7359ad79b000652.gif" title="move book up"&gt;&lt;/a&gt;&lt;img alt="Loading-trans" class="loading" id="loading_anim_434018960" src="http://www.goodreads.com/assets/loading-trans-3e04cd6ed6ad31063972e688820d7866.gif" style="display:none"&gt;&lt;a href="/shelf/move_up/174788201?redirect_url=%2Freview%2Flist%2F4111865%3Fformat%3Dhtml%26page%3D1%26shelf%3Dto-read" class="actionLink" data-method="post" id="hidden_link_434018960" rel="nofollow" style="display: none"&gt;&lt;img alt="up" src="http://www.goodreads.com/assets/up_arrow-7957f2bae9c3456ec7359ad79b000652.gif" title="move book up"&gt;&lt;/a&gt;
            &lt;img src="/assets/loading.gif" class="position_loading" style="display: none"&gt;
            &lt;input id="positions_174788201" name="positions[174788201]" value="5" type="text"&gt;
            &lt;script type="text/javascript"&gt;
  //&lt;![CDATA[
        var newTip = new Tip($('positions_174788201'), "            &lt;nobr&gt;\n              &lt;a class=\"button\" href=\"#\" onclick=\"savePositionChanges(4111865); return false;\"&gt;Save position changes&lt;\/a&gt; &amp;nbsp;\n              &lt;a href=\"#\" onclick=\"$(\'positions_174788201\').prototip.hide(); return false;\"&gt;close&lt;\/a&gt;\n            &lt;\/nobr&gt;\n", { style: 'creamy', stem: 'leftMiddle', hook: { tip: 'leftMiddle', target: 'rightMiddle' }, offset: { x: 5, y: 5 }, hideOn: 'imaginaryelement', showOn: 'click', width: 'auto', hideOthers: true });
        $('positions_174788201').observe('prototip:shown', function() {
          if (this.up('#box')) {
            $$('div.prototip')[0].setStyle({zIndex: $('box').getStyle('z-index')});
          } else {
            $$('div.prototip')[0].setStyle({zIndex: 6000});
          }
        });
  
  //]]&gt;
  &lt;/script&gt;            &lt;a class="actionLink" href="#" id="loading_link_434206980" method="post" onclick="$(this).hide(); $('loading_anim_434206980').show(); $('hidden_link_434206980').simulate('click');; return false;"&gt;&lt;img alt="down" src="http://www.goodreads.com/assets/down_arrow-61b0e7292c02b1dcfd3f75a7f9b6b7ad.gif" title="move book down"&gt;&lt;/a&gt;&lt;img alt="Loading-trans" class="loading" id="loading_anim_434206980" src="http://www.goodreads.com/assets/loading-trans-3e04cd6ed6ad31063972e688820d7866.gif" style="display:none"&gt;&lt;a href="/shelf/move_down/174788201?redirect_url=%2Freview%2Flist%2F4111865%3Fformat%3Dhtml%26page%3D1%26shelf%3Dto-read" class="actionLink" data-method="post" id="hidden_link_434206980" rel="nofollow" style="display: none"&gt;&lt;img alt="down" src="http://www.goodreads.com/assets/down_arrow-61b0e7292c02b1dcfd3f75a7f9b6b7ad.gif" title="move book down"&gt;&lt;/a&gt;
          &lt;/div&gt;
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field cover"&gt;&lt;label&gt;cover&lt;/label&gt;&lt;div class="value"&gt;      &lt;a href="/book/show/12074927-the-fractal-prince"&gt;&lt;img alt="The Fractal Prince (The Quantum Thief Trilogy #2)" src="http://photo.goodreads.com/books/1311105989s/12074927.jpg" title="The Fractal Prince (The Quantum Thief Trilogy #2)"&gt;&lt;/a&gt;
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field title"&gt;&lt;label&gt;title&lt;/label&gt;&lt;div class="value"&gt;    &lt;a href="/book/show/12074927-the-fractal-prince" title="The Fractal Prince (The Quantum Thief Trilogy #2)"&gt;
        The Fractal Prince
          &lt;span class="darkGreyText"&gt;(The Quantum Thief Trilogy #2)&lt;/span&gt;
  &lt;/a&gt;&lt;/div&gt;&lt;/td&gt;  &lt;td class="field author"&gt;&lt;label&gt;author&lt;/label&gt;&lt;div class="value"&gt;      &lt;a href="/author/show/2768002.Hannu_Rajaniemi"&gt;Rajaniemi, Hannu&lt;/a&gt;
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field isbn" style="display: none"&gt;&lt;label&gt;isbn&lt;/label&gt;&lt;div class="value"&gt;    
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field isbn13" style="display: none"&gt;&lt;label&gt;isbn13&lt;/label&gt;&lt;div class="value"&gt;    
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field asin" style="display: none"&gt;&lt;label&gt;asin&lt;/label&gt;&lt;div class="value"&gt;    
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field num_pages" style="display: none"&gt;&lt;label&gt;num pages&lt;/label&gt;&lt;div class="value"&gt;      &lt;span class="greyText"&gt;unknown&lt;/span&gt;
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field avg_rating"&gt;&lt;label&gt;avg rating&lt;/label&gt;&lt;div class="value"&gt;    3.67
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field num_ratings" style="display: none"&gt;&lt;label&gt;num ratings&lt;/label&gt;&lt;div class="value"&gt;    9
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field date_pub"&gt;&lt;label&gt;date pub&lt;/label&gt;&lt;div style="background: none repeat scroll 0% 0% Lightgrey;" class="value"&gt;      Sep 27, 2012
  &lt;/div&gt;&lt;/td&gt;  &lt;td class="field date_pub_edition" style="display: none"&gt;&lt;label&gt;date pub edition&lt;/label&gt;&lt;div class="value"&gt;      &lt;span class="greyText"&gt;unknown&lt;/span&gt;
  &lt;/div&gt;&lt;/td&gt;    &lt;td class="field rating"&gt;&lt;label&gt;my rating&lt;/label&gt;&lt;div class="value"&gt;
      &lt;span class="stars" id="stars12074927_4111865" onmouseout="mouseOutStars('12074927')"&gt;&lt;a rel="nofollow"&gt;&lt;img alt="didn't like it " class="star" id="star12074927_0" onclick="submitStars('12074927', 0, '/review/rate/12074927?rating=1', 4111865);  return false;" onmouseover="checkStars('12074927', 0)" src="/assets/layout/gr_orange_star_inactive.png" title="didn't like it" height="15" width="15"&gt;&lt;/a&gt;&lt;a rel="nofollow"&gt;&lt;img alt="it was ok " class="star" id="star12074927_1" onclick="submitStars('12074927', 1, '/review/rate/12074927?rating=2', 4111865);  return false;" onmouseover="checkStars('12074927', 1)" src="/assets/layout/gr_orange_star_inactive.png" title="it was ok" height="15" width="15"&gt;&lt;/a&gt;&lt;a rel="nofollow"&gt;&lt;img alt="liked it " class="star" id="star12074927_2" onclick="submitStars('12074927', 2, '/review/rate/12074927?rating=3', 4111865);  return false;" onmouseover="checkStars('12074927', 2)" src="/assets/layout/gr_orange_star_inactive.png" title="liked it" height="15" width="15"&gt;&lt;/a&gt;&lt;a rel="nofollow"&gt;&lt;img alt="really liked it " class="star" id="star12074927_3" onclick="submitStars('12074927', 3, '/review/rate/12074927?rating=4', 4111865);  return false;" onmouseover="checkStars('12074927', 3)" src="/assets/layout/gr_orange_star_inactive.png" title="really liked it" height="15" width="15"&gt;&lt;/a&gt;&lt;a rel="nofollow"&gt;&lt;img alt="it was amazing " class="star" id="star12074927_4" onclick="submitStars('12074927', 4, '/review/rate/12074927?rating=5', 4111865);  return false;" onmouseover="checkStars('12074927', 4)" src="/assets/layout/gr_orange_star_inactive.png" title="it was amazing" height="15" width="15"&gt;&lt;/a&gt;&lt;/span&gt;&lt;script language="javascript" type="text/javascript"&gt;starRatings[ratingIndex++] = [ '12074927', -1]; checkStars('12074927', -1);&lt;/script&gt;
      &lt;span id="reviewMessage12074927_4111865"&gt;&lt;/span&gt;
      &lt;span id="successMessage12074927_4111865"&gt;&lt;/span&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field shelves"&gt;&lt;label&gt;shelves&lt;/label&gt;&lt;div class="value"&gt;    &lt;span id="shelfList4111865_12074927"&gt;&lt;span id="shelf_174788201"&gt;&lt;a href="http://www.goodreads.com/review/list/4111865?shelf=to-read" class="shelfLink" title="View all books in Johan's to-read shelf."&gt;to-read&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;a class="shelfChooserLink smallText" href="#" onclick="window.shelfChooser.summon(event, {bookId: 12074927, chosen: [&amp;quot;to-read&amp;quot;]}); return false;"&gt;[edit]&lt;/a&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field review" style="display: none"&gt;&lt;label&gt;review&lt;/label&gt;&lt;div class="value"&gt;    &lt;span class="greyText"&gt;None&lt;/span&gt;
      &lt;a class="floatingBoxLink smallText" href="#" onclick="reviewEditor.summon(this, 12074927, 'review', {value: null}); return false;"&gt;[edit]&lt;/a&gt;
    &lt;div class="clear"&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field notes" style="display: none"&gt;&lt;label&gt;notes&lt;/label&gt;&lt;div class="value"&gt;      &lt;span class="greyText"&gt;None&lt;/span&gt;
        &lt;a class="floatingBoxLink smallText" href="#" onclick="reviewEditor.summon(this, 12074927, 'notes', {value: null}); return false;"&gt;[edit]&lt;/a&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field recommender" style="display: none"&gt;&lt;label&gt;recommender&lt;/label&gt;&lt;div class="value"&gt;    &lt;span class="greyText"&gt;none&lt;/span&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field comments" style="display: none"&gt;&lt;label&gt;comments&lt;/label&gt;&lt;div class="value"&gt;  &lt;a href="/review/show/265364012"&gt;0&lt;/a&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field votes" style="display: none"&gt;&lt;label&gt;votes&lt;/label&gt;&lt;div class="value"&gt;  &lt;a href="/rating/voters/265364012?resource_type=Review"&gt;0&lt;/a&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field read_count" style="display: none"&gt;&lt;label&gt;# times read&lt;/label&gt;&lt;div class="value"&gt;    0
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field date_started" style="display: none"&gt;&lt;label&gt;date started&lt;/label&gt;&lt;div class="value"&gt;    &lt;span class="greyText"&gt;not set&lt;/span&gt;
      &lt;a class="floatingBoxLink smallText" href="#" onclick="reviewEditor.summon(this, 12074927, 'started_at', {value: null}); return false;"&gt;[edit]&lt;/a&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field date_read"&gt;&lt;label&gt;date read&lt;/label&gt;&lt;div class="value"&gt;    &lt;span class="greyText"&gt;not set&lt;/span&gt;
      &lt;a class="floatingBoxLink smallText" href="#" onclick="reviewEditor.summon(this, 12074927, 'read_at', {value: null}); return false;"&gt;[edit]&lt;/a&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field date_added" style="display: none"&gt;&lt;label&gt;date added&lt;/label&gt;&lt;div class="value"&gt;  &lt;span title="January 21, 2012"&gt;
      Jan 21, 2012
    &lt;/span&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field date_purchased" style="display: none"&gt;&lt;label&gt;date purchased&lt;/label&gt;&lt;div class="value"&gt;    &lt;a class="smallText" href="#" id="add_for_date_purchased" onclick="new Ajax.Request('/review/update/12074927?format=json', {asynchronous:true, evalScripts:true, onFailure:function(request){Element.hide('loading_anim_206609');$('add_for_date_purchased').innerHTML = '&lt;span class=&amp;quot;error&amp;quot;&gt;ERROR&lt;/span&gt;try again';$('add_for_date_purchased').show();}, onLoading:function(request){;Element.show('loading_anim_206609');Element.hide('add_for_date_purchased')}, onSuccess:function(request){Element.hide('loading_anim_206609');Element.show('add_for_date_purchased');var json = eval('(' + request.responseText + ')');$('review_265364012').replace(json.html);if (typeof(toggleFieldsToMatchHeader) == 'function') {toggleFieldsToMatchHeader();}}, parameters:'owned_book[book_id]=12074927&amp;amp;partial=bookalike&amp;amp;view=table' + '&amp;amp;authenticity_token=' + encodeURIComponent('J5JjYi/D31hPm9w3u8hM35umQTh8bK3md4dVzpi4eKQ=')}); return false;"&gt;(add)&lt;/a&gt;&lt;img alt="Loading-trans" class="loading" id="loading_anim_206609" src="http://www.goodreads.com/assets/loading-trans-3e04cd6ed6ad31063972e688820d7866.gif" style="display:none"&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field owned" style="display: none"&gt;&lt;label&gt;owned&lt;/label&gt;&lt;div class="value"&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="field purchase_location" style="display: none"&gt;&lt;label&gt;purchase location&lt;/label&gt;&lt;div class="value"&gt;    &lt;a class="smallText" href="#" id="add_for_purchase_location" onclick="new Ajax.Request('/review/update/12074927?format=json', {asynchronous:true, evalScripts:true, onFailure:function(request){Element.hide('loading_anim_953979');$('add_for_purchase_location').innerHTML = '&lt;span class=&amp;quot;error&amp;quot;&gt;ERROR&lt;/span&gt;try again';$('add_for_purchase_location').show();}, onLoading:function(request){;Element.show('loading_anim_953979');Element.hide('add_for_purchase_location')}, onSuccess:function(request){Element.hide('loading_anim_953979');Element.show('add_for_purchase_location');var json = eval('(' + request.responseText + ')');$('review_265364012').replace(json.html);if (typeof(toggleFieldsToMatchHeader) == 'function') {toggleFieldsToMatchHeader();}}, parameters:'owned_book[book_id]=12074927&amp;amp;partial=bookalike&amp;amp;view=table' + '&amp;amp;authenticity_token=' + encodeURIComponent('J5JjYi/D31hPm9w3u8hM35umQTh8bK3md4dVzpi4eKQ=')}); return false;"&gt;(add)&lt;/a&gt;&lt;img alt="Loading-trans" class="loading" id="loading_anim_953979" src="http://www.goodreads.com/assets/loading-trans-3e04cd6ed6ad31063972e688820d7866.gif" style="display:none"&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field condition" style="display: none"&gt;&lt;label&gt;condition&lt;/label&gt;&lt;div class="value"&gt;    &lt;a class="smallText" href="#" id="add_for_condition" onclick="new Ajax.Request('/review/update/12074927?format=json', {asynchronous:true, evalScripts:true, onFailure:function(request){Element.hide('loading_anim_990684');$('add_for_condition').innerHTML = '&lt;span class=&amp;quot;error&amp;quot;&gt;ERROR&lt;/span&gt;try again';$('add_for_condition').show();}, onLoading:function(request){;Element.show('loading_anim_990684');Element.hide('add_for_condition')}, onSuccess:function(request){Element.hide('loading_anim_990684');Element.show('add_for_condition');var json = eval('(' + request.responseText + ')');$('review_265364012').replace(json.html);if (typeof(toggleFieldsToMatchHeader) == 'function') {toggleFieldsToMatchHeader();}}, parameters:'owned_book[book_id]=12074927&amp;amp;partial=bookalike&amp;amp;view=table' + '&amp;amp;authenticity_token=' + encodeURIComponent('J5JjYi/D31hPm9w3u8hM35umQTh8bK3md4dVzpi4eKQ=')}); return false;"&gt;(add)&lt;/a&gt;&lt;img alt="Loading-trans" class="loading" id="loading_anim_990684" src="http://www.goodreads.com/assets/loading-trans-3e04cd6ed6ad31063972e688820d7866.gif" style="display:none"&gt;
  &lt;/div&gt;&lt;/td&gt;&lt;td class="field format"&gt;&lt;label&gt;format&lt;/label&gt;&lt;div class="value"&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="field actions"&gt;&lt;label&gt;actions&lt;/label&gt;&lt;div class="value"&gt;    &lt;div class="actionsWrapper greyText smallText"&gt;
        &lt;div class="editLinkWrapper"&gt;&lt;a class="actionLinkLite editLink" href="#" id="loading_link_818479" onclick="new Ajax.Request('/review/edit/12074927', {asynchronous:true, evalScripts:true, onFailure:function(request){Element.hide('loading_anim_818479');$('loading_link_818479').innerHTML = '&lt;span class=&amp;quot;error&amp;quot;&gt;ERROR&lt;/span&gt;try again';$('loading_link_818479').show();}, onLoading:function(request){;Element.show('loading_anim_818479');Element.hide('loading_link_818479')}, onSuccess:function(request){Element.hide('loading_anim_818479');Element.show('loading_link_818479');}, parameters:'authenticity_token=' + encodeURIComponent('J5JjYi/D31hPm9w3u8hM35umQTh8bK3md4dVzpi4eKQ=')}); return false;"&gt;edit&lt;/a&gt;&lt;img alt="Loading-trans" class="loading" id="loading_anim_818479" src="http://www.goodreads.com/assets/loading-trans-3e04cd6ed6ad31063972e688820d7866.gif" style="display:none"&gt;&lt;/div&gt;
        &lt;div class="viewLinkWrapper"&gt;&lt;a href="/review/show/265364012" class="actionLinkLite viewLink nobreak"&gt;view »&lt;/a&gt;&lt;/div&gt;
        &lt;a href="/review/destroy/12074927?return_url=http%3A%2F%2Fwww.goodreads.com%2Freview%2Flist%2F4111865%3Fshelf%3Dto-read" class="actionLinkLite smallText deleteLink" data-confirm="Are you sure you want to remove The Fractal Prince from your books? This will permanently remove this book from your shelves, including any review, rating, tags, or notes you have added. To change the shelf this book appears on please edit the shelves." data-method="post" rel="nofollow"&gt;        &lt;img alt="Remove from my books" src="http://www.goodreads.com/assets/layout/delete.gif" title="Remove from my books"&gt;
          &lt;span class="label"&gt;remove book&lt;/span&gt;
  &lt;/a&gt;    &lt;/div&gt;
  &lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>