Patrioticcow
Patrioticcow

Reputation: 27058

jquery removeClass seems not to work, how to?

i have a simple example of using removeClass but it doesnt seem to work properly. Im not sure why i cant see the problem

html

<ul id="alljobs" class="hide">123</ul>
<ul id="jobs" class="hide">123</ul>

css

.hide{color:red;}

js

var x=1;

if (x ==1 ){
$('#jobs').removeClass('.hide');
}

in this case one ul text color should be black, but it isn't

any ideas?

here is my jsfiddle

thanks

Upvotes: 1

Views: 281

Answers (3)

user596075
user596075

Reputation:

$('#jobs').removeClass('hide');

You need to take out the period in your class name. The period is used in a selector for noting that the string to follow is a class name. But in the removeClass() function, the parameter is simply a string that is the class' name.

The fixed jQuery code, in total, would be this:

var x=1; 

if (x ==1 ){ 
$('#jobs').removeClass('hide'); 
} 

Upvotes: 7

thenetimp
thenetimp

Reputation: 9830

remote the . from your class name, it's not really part of the class name when using jquery.

Upvotes: 2

ShankarSangoli
ShankarSangoli

Reputation: 69915

Remove the dot(.) from class name.

$('#jobs').removeClass('hide');

Upvotes: 2

Related Questions