What is the shorthand to assign a CSS style and add the pixels on the same line? The following doesn't work though it should be exceptionally clear what I'm trying to do:
header.style.top = (h + 100)+px;
What is the shorthand to assign a CSS style and add the pixels on the same line? The following doesn't work though it should be exceptionally clear what I'm trying to do:
header.style.top = (h + 100)+px;
px
is not defined. I believe you are intending to concat a string. Observe the following...
header.style.top = (h + 100) + 'px';
JSFiddle Link - simplified demo
I believe you don't need to specify the px
value. It defaults to pixels
checkout this question: Using Javascript to add width to a HTML element
As found here http://javascript.info/tutorial/styles-and-classes-getcomputedstyle they say to enclose the px in brackets 'px'
. Like the above answers.