views:

48

answers:

2

Hi, using the Firebug console I'm trying to test whether this code is working:

$(window).bind("load", function() {
    $('#tab1link').click(function() {
        $('#tab2').hide();
        $('#tab2').removeClass('selected');
        $('#tab1').show();
        $('#tab1').addClass('selected');
    });

    $('#tab2link').click(function() {
        $('#tab1').hide();
        $('#tab1').removeClass('selected');
        $('#tab2').show();
        $('#tab2').addClass('selected');
    });

});

but this:

console.log($('#tab2').hasClass('selected'))

returns the error:

 TypeError: $("#tab2").hasClass is not a function { message="$("#tab2").hasClass is not a function",  more...}

Does anyone know why the above console command is incorrect? (Not a jQuery expert...)

Based on the link below, I think it should work... http://api.jquery.com/hasClass/

Thanks!

+1  A: 

Try refreshing the console/page because sometimes it doesn't properly assign $ to jQuery, assuming you're using Firebug ( it keeps the native $ function which ISNT jquery ).

You can confirm this with:

alert( $ == jQuery )

If this isn't it, then make sure you aren't using multiple libraries that use $.

Unrelated: You can also do $(function(){ /* code */ }); instead of binding on window load.

meder
Your test comes back true, so $ == jQuery.
aangel
Link to a demo.
meder
A: 

Try this instead:

console.log(jQuery('#tab2').hasClass('selected'))

It looks suspiciously like the $ is given up but still in use, like Prototype in included in the page and jQuery.noConflict() was called (which means $ != jQuery when you're running commands in the console later).

Nick Craver
I tried that and receive the same error. Using the test above, alert ($ == jQuery), I've confirmed that the $ should respond.
aangel