Why the JQuery syntax below is not correct:
$('#Footer').css({ right: 6%, bottom: 0 });
And this one is:
$('#Footer').css('right', '6%');
$('#Footer').css('bottom', '0开发者_如何转开发');
What is incorrect in the first code ?
Thanks in advance
6%
is not a number, so it must be specified as a string.
$('#Footer').css({ right: '6%', bottom: 0 });
you are missing ''
$('#Footer').css({ right: '6%', bottom: '0' });
for reference http://api.jquery.com/Types/#jQuery
because of your missing quotes
it should be
$('#Footer').css({ 'right': '6%', 'bottom': 0 });
$('#Footer').css({ 'right': '6%', 'bottom': 0 });
Is the right answer as Kimtho6 stated.
Kapa is universally mistaken in this instance. As the quotes are only optional when using single word properties; if you used his reasoning then your code would fail when getting the padding-right
property.
It's the same reason JSON requires quotes. Because quotes make property names universal. And because that's how JS and many other coding languages do not allow the -
character as standalone property names; because it was a math symbol before there was any computer coding languages.
Fail:
$('#Footer').css({ padding-top: '6%', padding-bottom: 0 });
Success:
$('#Footer').css({ 'padding-top': '6%', 'padding-bottom': 0 });
精彩评论