Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 334
Zak Avatar asked Dec 26 '10 15:12

Zak


People also ask

What does innerWidth () method do in jQuery?

The innerWidth() method returns the inner width of the FIRST matched element.

Does jQuery width include padding?

jQuery outerWidth() Method The outerWidth() method returns the outer width of the FIRST matched element. As the image below illustrates, this method includes padding and border.

What is CSS manipulation in jQuery?

The jQuery CSS methods allow you to manipulate CSS class or style properties of DOM elements. Use the selector to get the reference of an element(s) and then call jQuery css methods to edit it. Important DOM manipulation methods: css(), addClass(), hasClass(), removeClass(), toggleClass() etc.

How do I get padding in JavaScript?

To get an element's padding value using JavaScript, we can use the getComputedStyle and getPropertyValue methods.


1 Answers

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"
like image 62
BoltClock Avatar answered Nov 15 '22 14:11

BoltClock