Reputation: 9855
I've built a sliding DIV with a few anchors that when clicked I want to show their corresponding DIV.
When you click operations, however, it's a bit buggy. Surely there's a better way to do this? I dont think I've built it very well, so can anybody suggest impovements, or make it so that when one item is clicked the others are hidden?
At first I need the financial DIV showing which is providing to be a pain...
Upvotes: 0
Views: 348
Reputation: 171700
There are simple ways to manage this with one handler for all links. All you need is a way to create relationship between links and content. Here is one approach by adding one attribute to the links. You then set some class name that defines only the current one to make it easy to slide it back up
HTML:
<a class="finance-btn titlejob" href="#" data-class="finance">
JS:
$('.titlejob').click(function() {
var newContent = $('.' + $(this).data('class'));;
$('.content_active').removeClass('content_active').slideToggle("slow", function() {
newContent.slideToggle("slow").addClass('content_active');
});
return false;
});
Upvotes: 0
Reputation: 26909
Don't use toggle, call siblings.hide() on each panel switch.
Wrap the panels in a containing div (so Siblings().hide() only hides the other panels, not the header)
Upvotes: 0
Reputation: 680
I would suggest that you create a variable that would hold what is currently displayed. Upon clicking on a tab, it will hide the current one, show the new one, then set the new one as the current one.
I've modified your fiddle to demonstrate it: http://jsfiddle.net/t0nyh0/MZNyC/20/
Upvotes: 1
Reputation: 85
you can use the onClick() event in the buttons and use a function to tootle the buttons and reutilize it when the button is clicked. So if you add another button, pass the argument (wich button to do the "toggle") in the function.
Regards
Upvotes: 0