Change CSS rule in class using JQuery

前端 未结 8 1380
我在风中等你
我在风中等你 2020-12-05 04:40

I have a class in CSS

.Foo
{
  width:20px;
}

Using Jquery I would like to do something similar to this on an event:

$(\".Fo         


        
8条回答
  •  日久生厌
    2020-12-05 05:30

    You should be selecting an element with jQuery. You're aware that you aren't selecting the CSS class itself, correct?

    Once you have an element with class="Foo", you can select it as you have, and either set css properties manually like you're trying to do, or you can use add class like so:

    $(".Foo").addClass('Foo');

    Granted of course, since you're selecting the same class that you're adding, it doesn't really make sense.

提交回复
热议问题