title: Can't figure out how to correctly call an element
body: <p>I have some JQuery that does a ton of stuff with reordering and adding links to the nav, but the important part is that it's supposed to hide every nav link except for the first one (by looping through the nav) when the page loads. The way the loop works is that it hides every link that doesn't have the class attribute: <code>class="top"</code>. 
  This is working fine, except for when <code>var page = ""</code>. As you can see from the code, I'm trying to select the nav link that links to "index.php" and add the <code>class="top"</code> attribute to it when <code>var page = ""</code>. I don't know if this is right, but something appears to be breaking my entire javascript document. I don't even know if it's selecting the right element or adding the class attribute, because when <code>var page = ""</code> none of the nav links are hidden. </p>
  
  <p>Any ideas? Thanks for your help!</p>
  
  <p>This is the HTML of my navigation bar:</p>
  
  <pre><code>&lt;nav&gt;
      &lt;ul id='nav'&gt;
          &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="skillsets.php"&gt;Skillsets&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="gallery.php"&gt;Gallery&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="about.php"&gt;About&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="contact.php"&gt;Contact&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>This is the JQuery I'm using:</p>
  
  <pre><code>var is_mobile = false,
      page = document.location.pathname.match(/[^\/]+$/)[0];
  $(document).ready(function(){
      var ul = $('nav &gt; ul'),
          li = ul.children('li'),
          href = li.find('a[href*="'+page+'"]'),
          is404 = true;
      if($('#mobile').css('display')=='none') {
          is_mobile = true;       
      }
      if(is_mobile) {
          orderList();
          prepareList();
      }
      /************************************************************/
      /* Reorders the list relative to the page the user is on   */
      /**********************************************************/
      function orderList() {
          //remove the right border from the contact link
          $(li.find('a[href*="contact.php"]')).removeAttr('style');
          //move element to top
          ul.prepend(href.parent());
          //set top elements class to "top"
          $(href).attr( "class", "top" );
          if(page != ""){
              //loop through the nav elements
              li.children('a').each(function(){
                  //if the name of the page the user is on matches one of the nav links execute the command
                  if (page == $(this).attr('href')) {
                      is404 = false;
                  }
              });
              if (is404) {
                  //if the user is on a page not in the nav, add a 404 link at the top of the nav
                  ul.prepend("&lt;li&gt;&lt;a href='404NotFound.php' class='top'&gt;404&lt;/a&gt;&lt;/li&gt;");
              }else if(page == ""){
                  //set top links' class to "top"
                  $(li.find('a[href*="index.php"]')).attr( "class", "top" );
              }else{
                  $(href).attr( "class", "top" ); 
              }
          }
      };
      /*****************************************************************/
      /* Prepares the list to be dynamically expandable/collapsible   */
      /***************************************************************/
      function prepareList() {
          //loop through the nav elements and differentiate the first nav link and the remaining nav links
          li.children('a').each(function(){
              //check if the link has the class: "first"
              if ($(this).attr('class') == "top") {// attribute value matches variable value
                  //make the first nav link function as the button to open and close the nav
  
              } else {// attribute doesn't exist, or its value doesn't match variable value
                  //hide the remaining nav links with a slideUp animation
                  $(this).slideUp("slow");
              }
          });
      }
  });
  </code></pre>