user2451379
user2451379

Reputation: 23

Unable to remove all classes in td with jQuery

I am trying to remove colspan class but it is removing only create class.

<td class="create colspan">
</td>

if ($(this).prev().hasClass('colspan') || $(this).next().hasClass('colspan')) {
    alert('yes');
    } else {
         $(this).removeClass(); 
         $(this).removeClass('.colspan')
 }

Upvotes: 2

Views: 203

Answers (3)

Sandy
Sandy

Reputation: 23

$(this).removeClass('colspan create')

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82241

You dont need to pass class selector . in removeClass().so use:

$(this).removeClass('colspan')

to remove both classes colspan and create,use:

$(this).removeClass('colspan create')

Upvotes: 3

Felix
Felix

Reputation: 38102

You don't need . here, you just need to provide the name of your class to remove when using .removeClass():

$(this).removeClass('colspan')

Actually, when you use $(this).removeClass(), it's already remove all classes that is inside $(this) element including colspan and create.

Besides that, if you want to remove multiple classes like colspan and create which is your case, then you can separate the class name by space:

$(this).removeClass('colspan create')

Upvotes: 5

Related Questions