Global object variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • excitive
    New Member
    • Sep 2009
    • 2

    Global object variable

    Can't object variables be global?
    Why isn't following working?

    Code:
    <head>
    <script>
    	var o;
    	function func1()
    	{
    		o = document.getElementById("test1");
    		func2();
    	}
    	function func2()
    	{
    		o.innerHTML = "Changed";
    	}
    </script>
    </head>
    <body>
    	<a href="javascript:func1()" id="test1">Test Link</a>
    </body>
    If works if I move o.innerHTML = "Changed"; from func2() to func1().
  • excitive
    New Member
    • Sep 2009
    • 2

    #2
    Ah! It was my silly mistake and it is working now...

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      So what was the problem?

      Comment

      Working...