cicakman
cicakman

Reputation: 1990

Multiple classes just select the one clicked

Jquery Code:

$(".tog").toggle(
function() {
    $(".tog span").removeClass('stog');
    $(".tog span").addClass('stogm');
    $(this).next().slideDown('fast');
},
function() {
    $(".tog span").removeClass('stogm');
    $(".tog span").addClass('stog');
    $(this).next().slideUp('fast');
}
);

I have few side_cat_toggle classes, but i want the one i clicked only to take the changes above. Currently every classes of side_cat_toggle is changing and not the one i clicked.

How do i do it?

Thanks

Upvotes: 0

Views: 125

Answers (3)

Ayman Safadi
Ayman Safadi

Reputation: 11552

Try this:

$(".tog").click(function() {

    $(this).find('span').removeClass('stog').addClass('stogm');

    $(this).toggle(
        function() {
            $(this).next().slideDown('fast');
        },
        function() {
            $(this).next().slideUp('fast');
        }
    );
});

Upvotes: 0

Marko
Marko

Reputation: 72222

$(".tog").toggle(
function() {
    $("span", this).removeClass('stog').addClass("stogm");
    $(this).next().slideDown("fast");
},
function() {
    $("span", this).addClass('stog').removeClass("stogm");
    $(this).next().slideUp("fast");
}
);

Upvotes: 1

Joop Eggen
Joop Eggen

Reputation: 109547

$(".tog").click(
    var $that = $this;
    $this.toggle(... $that ... ));

Use $that to access $(".tog")

Upvotes: 0

Related Questions