2

I have replicated a toggle functionality from this site: http://www.williamsprofessionalpainting.com/FAQ.php

Here is the updated version which renders the basic toggle function with minimum CSS:

http://jsfiddle.net/NinjaSk8ter/yXNmx/

1
  • you tagged jquery but you dont use jqeury. In jquery this is very easy functionality. You can do it with the function toggle. Commented Mar 11, 2011 at 23:42

2 Answers 2

1

Your code is working fine, but jsFiddle is wrapping it in a function. In other words, it ends up looking something like:

window.onload = function() {
  function ToggleFAQ(Ans) {
    ...
  }  
};

The function is defined within the onload handler, so when your onclick tries to call it, it doesn't exist.

If you change the drop-down on the top-left of your fiddle to "no wrap", it all works fine. See this modified version.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for clueing me in about that, Im going to save that fiddle.
0

On your JSFiddle - if you change the wrap method to "no wrap(head)" and it simply works.

Alternatively - you can declare the function as a global var:

ToggleFAQ = function (Ans)
{
  //..
}

what renders as

jQuery(document).ready(function(){

  //when defined like this - ToggleFAQ  will still be visible when the 
  //"ready" event finishes.
  ToggleFAQ = function (Ans)
  {
     //..
  }

}

the wrap you selected puts your code in a function passed to jQuery's "dom-ready" event - and that's a closure that once is executed - all local variables are "vaporized".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.