How to make my function to be page specific or div id specific?
<p>I am writing javascript to my web pages, but there is a number of functions and loops, that i think are running in all pages, so the first one is running and failing on the second page. Because of this, the javascript function on the second page is not running.</p>

<p>Can anyone give me an idea of how to create page-specific functions or check the availability of an id? I don't use any frameworks.</p>

<p>thanks in advance.</p>

<p>my javascript code is :</p>

<pre><code>window.onload = function(){  
   var yellows = document.getElementById('magazine-brief').getElementsByTagName('h2');  
   var signUp = document.getElementById('signup-link');      
    function animeYellowBar(num){  
      setTimeout(function(){  
          yellows[num].style.left = "0";  

          if(num == yellows.length-1){  
              setTimeout(function(){  
                  signUp.style.webkitTransform = "scale(1)";  
              },num * 250);  
          }  
      }, num * 500);  
    }
    for (var i = 0; i &lt; yellows.length; i++){  
      animeYellowBar(i);  
    }

    alert("alert second page");  
}
</code></pre>

<p>in this code, the alert message not working on second page. any idea?</p>
