Robert Granlund
asked on
jQuery Toggle
I have a piece of code that toggles open parts of <ul> when you click on a PLUS sign. And then it closes again, when it is clicked. There are many of these on a large menu. What I would like to add to the script is that if you click on a PLUS sign and there are other plus sigs that have been toggled open, they will close, so only one one toggled are is open at a time. The following script opens the ul but then it closes it again right away. Can anyone help me sort this out?
$(function() {
var $sublinks = $('.sublinks');
$('.viewmore').click(function(e) {
e.preventDefault();
$(this).closest('ul').find('.sublinks').toggle();
var text = ($(this).text() == '+') ? '-' : '+';
$(this).html(text);
var $ans = $(this).next(".sublinks").stop(true).slideToggle(100);
$sublinks.not($ans).filter(':visible').stop(true).slideUp();
});
});
ASKER
That does the same thing. It opens it and closes it immediatley: http://cohr-dev-ee01.azurewebsites.net/
Click on Products and then click on the first PLUS sign to see what I mean.
Click on Products and then click on the first PLUS sign to see what I mean.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I implement that on my page, there only thing it still does is change the plus to minus and nothing opens
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window