Connecting Tech Pros Worldwide Help | Site Map

Global object variable

Newbie
 
Join Date: Sep 2009
Posts: 2
#1: Sep 29 '09
Can't object variables be global?
Why isn't following working?

Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script>
  3.     var o;
  4.     function func1()
  5.     {
  6.         o = document.getElementById("test1");
  7.         func2();
  8.     }
  9.     function func2()
  10.     {
  11.         o.innerHTML = "Changed";
  12.     }
  13. </script>
  14. </head>
  15. <body>
  16.     <a href="javascript:func1()" id="test1">Test Link</a>
  17. </body>
If works if I move o.innerHTML = "Changed"; from func2() to func1().
Newbie
 
Join Date: Sep 2009
Posts: 2
#2: Sep 29 '09

re: Global object variable


Ah! It was my silly mistake and it is working now...
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#3: Oct 1 '09

re: Global object variable


So what was the problem?
Reply

Tags
global, object, variable


Similar JavaScript / Ajax / DHTML bytes