SeanKilleen
SeanKilleen

Reputation: 8977

jQuery fade in active element, fade out inactive elements

Update

Using:

$(event.currentTarget).fadeTo(0, 1);

Seems to work, while using:

$('.btn .active').fadeTo(0, 1);

Does not. Any idea why?

The Code

jsFiddle link here: http://jsfiddle.net/SeanKilleen/fwerK/

JavasScript code below:

var global_loggedOnUser = "User1";

$(document).ready(function () {

    var viewmodel = (function () {
        this.feedbacktype = ko.observable("None");
        this.currentPage = ko.observable(location.href);
        this.currentUsername = global_loggedOnUser;

        this.updateFeedbackType = function (item, event) {
            var newText = $(event.currentTarget).children("span").text();
            $('#buttonList button').removeClass('active');
            $(event.currentTarget).addClass('active');

            feedbacktype(newText);
            $('.btn').not('.active').fadeTo('fast', 0.3);
            $('.btn .active').fadeTo('fast', 1);
        };



        return {
            pageUserIsOn: currentPage,
            theUser: currentUsername,
            feedbackType: feedbacktype
        };
    })();


    ko.applyBindings(viewmodel);
});

The Goal

I'm trying to accomplish this by adding an "active" class to the button and removing it from all others, and then performing the fade based on class.

The Issue

What am I missing?

Upvotes: 1

Views: 1232

Answers (1)

omma2289
omma2289

Reputation: 54629

Remove the space between the classes, you want to select elements with both classes not .active descendants of .btn

$('.btn .active').fadeTo('fast', 1);

should be

$('.btn.active').fadeTo('fast', 1);

Updated fiddle

Upvotes: 2

Related Questions