0

I'm attempting to update the css within a div using its id via :

$(this.id).removeClass("myCss");

Should'nt this work ?

4

5 回答 5

7

Your selector is wrong:

$(this).removeClass("myCss");

Or, if you want to use the id, you'd need to concatenate it in:

$( "#" + this.id ).removeClass("myCss");

But that's really not necessary if this references your element to begin with.

于 2012-05-18T15:10:12.073 回答
5

To select object by ID you should use # prefix:

$("#" + this.id).removeClass("myCss");

Otherwise, use just:

$(this).removeClass("myCss");
于 2012-05-18T15:10:03.783 回答
3

No, it shouldn't :-) Just do

$(this).removeClass('myCss');

When selecting elements by "id" value, you have to include a leading "#" before the string. There's no point to doing that, however, if you've already got a reference to the DOM node.

于 2012-05-18T15:10:16.463 回答
1

you should do:

$(this).removeClass("myCss");
于 2012-05-18T15:10:46.697 回答
1

Here is the right code:

$(this).removeClass('myCss')
于 2012-05-18T15:11:12.547 回答