Struggling to pick the right JQuery elements for my portfolio site. The aim is to show/hide the .inner
(Task) items by clicking on the .outer
(Category) items, complete with rotating .arrow
s when the menu expands.
Check out a similar question, along with this jsfiddle.
Kudos to Tats_innit for the initial response.
The HTML looks like this:
<li class="outer" hook="01">
<div class="arrow"></div>
Category 1
</li>
<li class="inner" id="menu-01">
Task 1
</li>
<li class="inner" id="menu-01">
Task 2
</li>
<li class="inner" id="menu-01">
Task 3
</li>
<li class="outer" hook="02">
<div class="arrow"></div>
Category 2
</li>
<li class="inner" id="menu-02">
Task 1
</li>
<li class="inner" id="menu-02">
Task 2
</li>
<li class="inner" id="menu-02">
Task 3
</li>
And here's the jquery code:
$(document).ready(function(){
$('.outer').click(function(){
var elem = $('#menu-'+$(this).attr('hook')),
arrow = $(this).children('.arrow')
if (!elem.is(':visible')) {
arrow.rotate({animateTo:90, duration:128});
} else {
arrow.rotate({animateTo:0, duration:128});
}
elem.slideToggle('128ms', function() {
});
return false;
});
});
I'm aware that I need to modify
var elem = $('#menu-'+$(this).attr('hook'))
but unsure how to display all instances of .inner
.
I opted not to nest the .inner
elements due to having a hover state background-color: #f1f1f1;
for the .outer
class.