By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,567 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,567 IT Pros & Developers. It's quick & easy.

Function not defined

P: 6
I'm including a script in my header. That script contains a function, in the body part of the html page I try to call that function. But firebug says its not defined. I've tried moving the script include even after the links.
Can someone help!?
Jul 7 '08 #1
Share this Question
Share on Google+
12 Replies

Expert 100+
P: 1,654
This should not happen unless the function is being created on some event (which is still to be called), or you have a variable with its name same as the function's.
Jul 7 '08 #2

P: 6
So, how can I fix it?
Jul 7 '08 #3

Expert Mod 15k+
P: 16,027
You can start by posting your code (using code tags). It's difficult to point out a problem without seeing code.
Jul 7 '08 #4

P: 6
My js is:
Expand|Select|Wrap|Line Numbers
  1. function expand(el){
  2. var element = el.ClassName;
  3. el = el.parentNode; el.getElementsByClassName(element+"Text").style.display="block";
  4. }
And my html:
<div class="subContainer">
<div class="blue" onClick="expand(this);">Home</div>
<div class="blueText">Hi</div>
Jul 8 '08 #5

Expert 100+
P: 1,654
getElementsByClassName is implemented recently, so only the latest versions of Firefox, Opera and Safari support it. Have a look at this page.

Perhaps this is causing the problem.
Jul 8 '08 #6

P: 6
Again. What would I do?
Jul 8 '08 #7

Expert 100+
P: 1,654
Try to utilize other DOM function to get the same results.

You may find these useful:
Jul 8 '08 #8

P: 6
It doesn't make a difference. Its the function thats "undefined". I've already tried your solution.
Jul 8 '08 #9

Expert Mod 15k+
P: 16,027
You've got two more problems. ClassName should be className, and getElementsByClassName returns a list/array of elements, so you need to index the result, e.g. getElementsByClassName(...)[0].style...

Of course, for those browsers that don't support getElementsByClassName, just include a script that creates the function (there's many examples if you search).
Jul 8 '08 #10

P: 6
It works!! THANKS!!!!!!
Jul 8 '08 #11

Expert Mod 15k+
P: 16,027
Glad to hear it! Post back to the forum if you have anymore questions.
Jul 9 '08 #12

P: 9
thats good you got it!

Jul 9 '08 #13

Post your reply

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