-4

What is wrong with my JQuery code?

<script type="text/javascript">
    $(".header").click(function () {

$header = $(this);
//getting the next element
$content = $header.next();
//open up the content needed - toggle the slide- if visible, slide up, if not slidedown.
$content.slideToggle(500, function () {
    //execute this after slideToggle is done
    //change text of header based on visibility of content div
    $header.text(function () {
        //change text based on condition
        return $content.is(":visible") ? "Collapse" : "Expand";
    });
});
</script>

When I hover over the closing script tag it says "Expecting more source characters".

  • 1
    It would help if the title to your question actually described the question. It doesn't matter if you're new to something. – Andrew Oct 21 '14 at 16:41

1 Answers1

3

You've only closed two of the anonymous functions that you've declared (and the enclosing function calls). Try adding another }); before </script>.

Will Vousden
  • 32,488
  • 9
  • 84
  • 95
  • 2
    [It becomes **much** more obvious if OP bothered to indent his/her code](http://pastebin.com/szQDZdgq). – h2ooooooo Oct 21 '14 at 16:39
  • Why is everyone grumpy. I'm sorry I didn't indent my code. :( – user3715441 Oct 21 '14 at 16:43
  • @user3715441 because if you properly indent you have a far better chance of spotting syntax errors caused by missing braces ... and wouldn't be asking the question you asked – charlietfl Oct 21 '14 at 16:45
  • 2
    @user3715441 I apologize if I seem grumpy - it's solely because this is a problem that could be fixed by better standards. Instead of getting down over it, remember it till next time. Know that your problem was mainly solved due to indentation and realize how important it is. Programmers learn from their mistakes, and we make a lot of them. It's only after staring blindly at an obvious syntax error for hours that we never *ever* make the same mistake again. – h2ooooooo Oct 21 '14 at 16:45