Zak
Zak

Reputation: 2698

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?

Upvotes: 15

Views: 39833

Answers (2)

epascarello
epascarello

Reputation: 207557

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

Upvotes: 0

BoltClock
BoltClock

Reputation: 724452

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"

Upvotes: 32

Related Questions