title: Uncaught TypeError with my script
body: <p>I need some help, I don't know why in some websites it not error, but some websites it is error show up.</p>
  
  <p>Its show up the error notice in my console: Uncaught TypeError: Cannot read property 'length' of undefined.</p>
  
  <p>Any advice is thanks so much.</p>
  
  <pre><code>jQuery(document).ready(function(){
  jQuery( ".pagenav.home .menu &gt; li:first-child a" ).addClass('important_color');
  if (jQuery( ".menu-fixedmenu" ).length) {
      jQuery( ".menu-fixedmenu .menu a" ).each(function() {
          var id  = jQuery(this).attr('href');
          var lenght_id  = id.length;//***this line code error***
          if (typeof id !== "undefined" &amp;&amp; lenght_id &gt; 2) {
          if(id.search("#") != -1 &amp;&amp; id.search("http")){
              jQuery( window ).scroll(function() {
  
                  if(jQuery(id).isOnScreen()){
                      jQuery(id+' h2').removeClass('fadeInDown');
                      jQuery(id+' h2').addClass('animated fadeInUp');
                      var newid = id.split("#");
                      if(document.getElementById(newid[1]).getBoundingClientRect().top &lt; 250){
                          jQuery( ".fixedmenu .menu &gt; li a[href='"+id+"']" ).addClass('important_color');
                          }
  
                      else{
                          jQuery( ".fixedmenu .menu &gt; li a[href='"+id+"']" ).removeClass('important_color');
                      }
  
                  }
                  else{
                      if(id != jQuery( ".menu &gt; li:first-child a" ).attr('href') )
                          jQuery( ".fixedmenu .menu &gt; li a[href='"+id+"']" ).removeClass('important_color');
                          if(jQuery(this).scrollTop() &gt; 700)
                              jQuery( ".menu-fixedmenu .menu &gt; li:first-child a" ).removeClass('important_color');
                          else
                              jQuery( ".menu-fixedmenu .menu &gt; li:first-child a" ).addClass('important_color');
  
                          jQuery(id+' h2').removeClass('fadeInUp');
                          jQuery(id+' h2').addClass('animated fadeInDown');
                      }
  
              });
          }
          }
      });
  }
  </code></pre>
  
  <p>});</p>