0

I am having trouble with jQuery Slide Toggle.

$(document).ready(function() {
    $("a").click(function() {
    $(this).parent().parent().children("p").Toggle(400);
    return false;
    });
    });

I have a bunch of posts on the page pulled from a database, and they are structured like this (pseudo HTML)

<div post>
    <div float-left location/timeInfo></div>
    <div float-right bandInfo><a>slideToggleLink</a></div>
    <p>theToggledElement</p>
</div>

When I click the link, the jQuery function is not called, but I cannot see what the problem is.

2
  • 1
    What is "pseudo HTML"? Will a pseudo answer work? Commented Feb 11, 2012 at 0:42
  • What do you think pseudo HTML is? I didn't want to post the whole thing so I used a pseudo mark-up to give the gist of the structure of the elements.... because I believed that it was the structure which was part of the problem, whereas now we know it isn't. Commented Feb 11, 2012 at 1:10

3 Answers 3

1

jQuery does not have a Toggle() method.

You mean slideToggle().

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

5 Comments

jQuery does have a .toggle() method. It's just not spelled .Toggle().
@elclanrs, yes, the OP wants it to slide. It does not change the fact that jQuery has a "toggle" method, contrary to the wording of this answer.
@Sparky672: My answer is case-sensitive.
Yes, your answer is technically correct. However some may read it and think there's no toggle method at all. I just made my comment as a point of clarification, more than correction.
.toggle() is actually a nicer animation. I'm keeping it. Thanks, guys!
1
$(this).parent().parent().children("p").Toggle(400);

Bad for performance and Toggle() does not exist.
Replace with:

$('#post').find('p').slideToggle(400);

5 Comments

Well, you should post your not pseudo html then.
Meh. It's JavaScript... I don't really care about performance.
Ok, well, bit by bit you'll end up with such bloated code that is not even gonna run.
How do you even know that? This could be the only JavaScript/jQuery in the whole site for all you know.
Do whatever you want. First, if you're asking this question is because your knowledge of jQuery/js is not as good as you think and second, performance should be a priority in any case. I'm just showing you what I believe is the right way to do it by experience. Answers like "Meh. It's JavaScript" are no good, and it'll bite you later on.
1

You're asking about jQuery "Slide Toggle" but your code is using something called .Toggle(), which does not exist as it is spelled.

It should be .slideToggle() or just .toggle() (note: the lack of capital T in the second). However, there is no sliding/animation with .toggle().

1 Comment

Damn. That was dumb. Thanks, anyway.

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.