469,307 Members | 1,999 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,307 developers. It's quick & easy.

Global object variable

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().
Sep 29 '09 #1
2 1553
Ah! It was my silly mistake and it is working now...
Sep 29 '09 #2
acoder
16,027 Expert Mod 8TB
So what was the problem?
Oct 1 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by Matt | last post: by
4 posts views Thread by Andrew V. Romero | last post: by
5 posts views Thread by Richard A. DeVenezia | last post: by
41 posts views Thread by Miguel Dias Moura | last post: by
9 posts views Thread by Shapper | last post: by
16 posts views Thread by Roman Ziak | last post: by
112 posts views Thread by istillshine | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.