0

Struggling with where to start on this one, apologies for not much code.

Using slide toggle to display a div when a is clicked.

a currently has a background image with a defined position. I've created a sprite image, so that when the link is clicked, the background position will change to show a downwards pointing arrow (like a typical expanding list.)

How can I build into the function that when a is clicked, a class of arrowDown is added?

JS Fiddle

I'd like to add a class to this link:

<a>See opening times</a>

CSS needing to be added using classname arrowDown

a.arrowDown
{
    background-position: 2px -9px;
    }

Function:

$('.timeList a').click(function(e) {
    $(this).next().slideToggle('slow');
});
4

1 回答 1

3

您可以使用toggleClass方法:

$('.timeList a').click(function(e) {
    $(this).toggleClass('arrowDown').next().slideToggle('slow');
});
于 2013-03-08T10:47:55.820 回答