Reputation: 27
How do I change the padding-left
for an element in JavaScript? I have used this code and it works:
$(".number_1").stop().animate({height: '295px', width: '210px', opacity: 1}, 100);
However, when I add padding-left
to the code, it doesn't work:
$(".number_1").stop().animate({padding-left: '10px', height: '295px', width: '210px', opacity: 1}, 100);
How do I add padding-left
in code for it to work?
Upvotes: 1
Views: 1937
Reputation: 1477
You have to wrap the style rule in quotes:
.animate({'padding-left' : '20px' });
Or you can use this:
$("#p1").animate({paddingLeft:"+=100px"});
Here is a W3Schools Tryit Editor demonstrating how to use 'padding-left' or 'paddingLeft' in JQuery animations.
Upvotes: 1
Reputation: 12127
add quote(")
if using padding-left
or change first latter into upper case if properly have -
then use paddingLeft
$(".number_1").stop().animate({paddingLeft: '10px' ,height: '295px' ,width: '210px' ,opacity: 1}, 100);
OR
$(".number_1").stop().animate({"padding-left": '10px' ,height: '295px' ,width: '210px' ,opacity: 1}, 100);
Upvotes: 1
Reputation: 6004
String in key for objects without quotes only work when they can be parsed successfully. Add quotes around padding left and that should work.
$(".number_1").stop().animate({"padding-left": '10px' ,height: '295px' ,width: '210px' ,opacity: 1}, 100);
Upvotes: 1
Reputation: 451
Use paddingLeft
when you're working with javascript, although in this specific case 'padding-left'
might also work (not entirely sure on that though, as that would be a jQuery specific implementation thing).
$(".number_1").stop().animate({paddingLeft: '10px' ,height: '295px' ,width: '210px' ,opacity: 1}, 100);
And just a general tip, you should not put a space before the comma, but after it.
Upvotes: 0