jQuery include variable as class name

Running into some weird issue, can't quite figure out what's wrong. No errors popping up on my console.

I'm trying to filter my selector with a variable as it's class. See jsFiddle and below

Thanks!

http://jsfiddle.net/danielredwood/SUxQx/2/

JavaScript:

$('.titles li').click(function() {
    $(this).addClass('selected').siblings().removeClass('selected');

    var selected = $(this).attr('class').replace(' selected', ''),
            next = $('.lyrics article').hasClass(selected);

    $('#w').html(selected); //for testing, shows what the value is
    $('#x').html(next); //ditto

    $('.shown').fadeOut(400, function() {
        $(this).removeClass('shown');
        next.fadeIn(400).addClass('shown');
   });
});

Answers


Pretty sure this:

next = $('.lyrics article').hasClass(selected);

...should be this:

next = $('.lyrics article.' + selected);

...since .hasClass() returns a boolean.


Or you could do this instead (gives the same result):

next = $('.lyrics article').filter('.' + selected);

JSFIDDLE DEMO


Need Your Help

onKey listner works properly on emulator, but not working on android device

android android-layout android-fragments

I'm working on a android project in which i need to change a table layout according to the changes on a edit text view. The code work properly on emulator. But it doesn't works on actual device. Al...

REST Web Service - Different Types for Get and Create

c# web-services rest asp.net-web-api

With ASP.Net Web Api, is it ok / good practice for your GET endpoint to return a different type than your POST endpoint accepts?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.