Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5957445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:24:05+00:00 2026-05-22T18:24:05+00:00

I have a class in CSS .Foo { width:20px; } Using Jquery I would

  • 0

I have a class in CSS

.Foo
{
  width:20px;
}

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

$(".Foo").css("width", "40px");

This doesn’t work. Is this the wrong approach? Should I use addClass() and removeClass()?

EDIT: I figured out my problem. This command does in fact work. In my particular application I hadn’t created the elements using the class before I used the command, so when they were created nothing was changed.

Basically this command doesn’t change the CSS style rule, just the elements using the class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:24:05+00:00Added an answer on May 22, 2026 at 6:24 pm

    jQuery.css will find all existing elements on the page that have the Foo class, and then set their inline style width to 40px.

    In other words, this doesn’t create or change a css rule — if you dynamically add an element with the Foo class, it would still have a width of 20px, because its inline style hasn’t been set to override the default CSS rule.

    Instead, you should use addClass and removeClass and control the styles in your static CSS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this html: <div class=foo parent> <div class=child></div> </div> with some css: .foo{
I have this class on CSS : .mgmtError{ width:716px; float:left; background-color:#FF0000; padding:10px; text-align:center; }
I have a css rule like this: .foo:active { background-position: 0px -382px; } .foo
I have a CSS class defined, call it: <style type=text/css> .Foo { position: fixed;
For example I have this css class: .class{ background:#FFF; border:1px solid #ccc } And
I have an element like this: <p>My text with a <strong class=highlighted>sample highlight</strong>.<p> And
I have a CSS class called grid which I place on my tables. I
Let's say we have defined a CSS class that is being applied to various
I have a user avatar on my website. Simple image tag: <img src=foo.jpg class=userphoto
I have a div with the following CSS class defined: <div class=ui-button ui-state-active>bla bla

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.