0
In JavaScript, can you change an elementâs attribute value to a variable?
When changing an attribute of an HTML element, can you set the attribute value to a predefined variable in JavaScript? For example: var elem = document.getElementByTagName(âdivâ); desiredHeight = â100pxâ; elem[0].style.height = desiredHeight; I know that in this simplified example you wouldnât need a variable if it was always going to be 100px, but mine varies in the code so i was wondering if using a string variable would work when setting and elementâs attribute?
1 Answer
+ 1
Yes of course "100px" is a string just like
var myVar = "100px";