简体   繁体   中英

How do you change the padding of an element in jQuery?

I am using the following code

$("#numbers a").css({
"color":"white",
"text-decoration":"none",
"padding:":"5px"
});

The color and text-decoration change just fine, but the padding is not added to the element. How should I fix this?

You have a stray colon in your padding property which is causing it to not be recognized:

"padding:":"5px"

Remove it and it should work:

"padding":"5px"

In the : is just a typo in to your post, you might be confused with padding and inline elements.

Your selector "#numbers a" hints you are referencing an anchor tag. An anchor tag is an inline element and inline elements do not have padding on all sides. Nice article on padding|widths with inline elements

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM