How do you see if $(this) has a certain class?

Posted by cf_PhillipSenn on Stack Overflow See other posts from Stack Overflow or by cf_PhillipSenn
Published on 2010-04-22T22:41:46Z Indexed on 2010/04/22 22:43 UTC
Read the original article Hit count: 85

Filed under:

I have:

$('th a').click(function() {
   var $th = $(this).closest('th');
   $th.toggleClass('selected');

How do I say:

if ($th('.selected')) {
    alert('selected');
} else {
    alert('not selected');
}

© Stack Overflow or respective owner

Related posts about jQuery