/    Sign up×
Community /Pin to ProfileBookmark

jQuery Accordion Menu

jQuery Accordion Menu

Hi all

I’m using a simply Accordion menu with a div for the button and a div for the content.

[url]http://www.ttmt.org.uk/forum/[/url]

HTML

[code]
<div class=”sideNavBtn”>
<h2>Button One </h2>
</div>
<div class=”sideNavContent”>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu,
</p>
</div>
[/code]

jQuery

[code]
<script type=”text/javascript” charset=”utf-8″>

$(‘div.sideNavBtn’).click(function() {
$(‘div.sideNavBtn h2’).css(‘color’,’#666′);
$(this).css(‘color’,’red’);
$(‘div.sideNavContent’).slideUp(‘normal’);
$(this).next().slideDown(‘normal’);
});

$(“div.sideNavContent”).hide();

</script>
[/code]

The button div contains a h2 tag with the button name.

When the button is clicked I would like to change the color of that h2 tag.

How can I target the h2 tag of the button clicked. I want to do something like

[code]
$(this.h22).css(‘color’,’red’);
[/code]

Also how can I have a slideToggle on the button so clicking will open and close the container and clicking another button will close any open container like it does now.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@cbVisionDec 14.2011 — Close ?

You look at it like this ... give me all the H2's within "this":

$('h2', this).css('color','red');
×

Success!

Help @ttmt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...