Function not defined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nile
    New Member
    • Jul 2008
    • 6

    Function not defined

    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!?
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    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.

    Comment

    • Nile
      New Member
      • Jul 2008
      • 6

      #3
      So, how can I fix it?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You can start by posting your code (using code tags). It's difficult to point out a problem without seeing code.

        Comment

        • Nile
          New Member
          • Jul 2008
          • 6

          #5
          My js is:
          Code:
          function expand(el){
          var element = el.ClassName;
          el = el.parentNode; el.getElementsByClassName(element+"Text").style.display="block";
          }
          And my html:
          [html]
          <div class="subConta iner">
          <div class="blue" onClick="expand (this);">Home</div>
          <div class="blueText ">Hi</div>
          </div>
          [/html]

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            getElementsByCl assName 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.

            Comment

            • Nile
              New Member
              • Jul 2008
              • 6

              #7
              Again. What would I do?

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                Try to utilize other DOM function to get the same results.

                You may find these useful:
                getElementById
                getElementsByTa gName
                firstChild
                lastChild
                previousSibling
                nextSibling
                parentNode

                Comment

                • Nile
                  New Member
                  • Jul 2008
                  • 6

                  #9
                  It doesn't make a difference. Its the function thats "undefined" . I've already tried your solution.

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    You've got two more problems. ClassName should be className, and getElementsByCl assName returns a list/array of elements, so you need to index the result, e.g. getElementsByCl assName(...)[0].style...

                    Of course, for those browsers that don't support getElementsByCl assName, just include a script that creates the function (there's many examples if you search).

                    Comment

                    • Nile
                      New Member
                      • Jul 2008
                      • 6

                      #11
                      It works!! THANKS!!!!!!

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Glad to hear it! Post back to the forum if you have anymore questions.

                        Comment

                        • josefdesousa
                          New Member
                          • Jul 2008
                          • 9

                          #13
                          thats good you got it!

                          jose

                          Comment

                          Working...