0

I created this fiddle from code found on Stack, but it is firing an error. Can you help please.

My Fiddle: http://jsfiddle.net/422steve/DVNGc/

Original anser : https://stackoverflow.com/a/13000179/501173

Error I am getting is: TypeError: $allExtended.slideUp() is not a function

js:

$('.holder').on('click','a',function(e){   
    e.preventDefault();
    var $allExtended = $(this).closest('.wrapperdoo').find('.extended'),
        $extended = $allExtended.eq( $(this).index() ),        
        doIt= ($extended.is(':visible')) ? $extended.slideUp() : ($allExtended.slideUp()) ($extended.slideDown());   
});
1
  • It does not even has a correct syntax. ($allExtended.slideUp()) ($extended.slideDown()) What is this? Commented Nov 18, 2012 at 3:40

2 Answers 2

2

Here is what is going on - in your ternary operation, on the last line, you are trying to call two functions. That is not possible. You need to use an if block. Here is how I rewrote it. I don't know if you are using the doIt variable for any purpose, but you will want to check for undefined:

$('.holder').on('click','a',function(e){   
    e.preventDefault();
    var $allextended = $(this).closest('.wrapperdoo').find('.extended'),
        $extended = $allextended.eq( $(this).index() ),
        doIt = undefined;

    if ($extended.is(":visible")) {
        doIt = $extended.slideUp();            
    } else {
        $allextended.slideUp();
        doIt = $extended.slideDown();
    }  
});​

--- EDIT ---

To add the class to the href that is being clicked, just do it like this, in the function:

$(this).addClass('class');

If you want to remove the class when you are done, do it like this. First, assign the this variable as a global variable (so the this variables don't get mixed up), like so:

var sender = $(this);

Then, in your slideUp() or slideDown() functions, the second parameter is a callback for when it is completed:

$allextended.slideUp(500, function() { sender.removeClass('class'); });
Sign up to request clarification or add additional context in comments.

1 Comment

one slight issue. I need to append a class to the a href that triggers the slide down, as within the container div there are other a href links. Is there a fix for this that you can think of, lets say the a href class was .placed
1

($allextended.slideUp()) ($extended.slideDown()) is very wrong.
The code you wrote calls slideUp(), then calls the return value of slideUp as a function, passing slideDown().

It looks like you're trying to run two statements; to do that, you need an if block.

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.