views:

50

answers:

1

I tried to make an accordion effect with JavaScript based off this video altering a few things like using an input button instead of a link for the selector. However for some reason it's not working. Firefox error console outputs unkown pseudo-class or pseudo-element "visible" everytime I try to use it. What's the problem?

$("div.example").hide();
$("input.exampleButton").click(function(){
    $("div.example:visible").slideUp("slow");
    $(this).parent().next().slideDown("slow");
    //return false; if you don't want the link to follow
});

Here is the HTML

input type="button" value="See An Example" class="exampleButton" />
<div class="example">
    ...content
</div>
input type="button" value="See An Example" class="exampleButton" />
<div class="example">
    ...content
</div>
+1  A: 

You can ignore the warning in the console. The reason the code is not working is that the markup structure doesn't match the traversal done by the Javascript. Each <input> should probably be inside a <div>, so that the call to parent().next() will correctly go from the input to the <div class="example"> following it. You're also missing the opening < on the inputs but I assume that's a copy/paste error.

Working markup:

<div>
    <input type="button" value="See An Example" class="exampleButton" />
</div>
<div class="example">
    ...content
</div>
<div>
    <input type="button" value="See An Example" class="exampleButton" />
</div>
<div class="example">
    ...content
</div>
interjay
Thanks for the help! Is there a way I could do it without the div and somehow change the JavaScript only? I'm not quite fundamentally understanding why it doesn't work.
Dennis Hodapp
@Dennis: You can remove the call to `parent()`. Then `next()` will go from the `<input>` to the element following it.
interjay