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');
}
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');
}
You're looking for the hasClass method:
if ($th.hasClass('selected')) //No dot
In general, you're looking for the is method:
if ($th.is('.selected')) //Yes dot
Since the is method takes a selector, you need to include a ..
if ($th.hasClass('selected')) {
alert('selected');
} else {
alert('not selected');
}