It is necessary to transfer diva width which value is calculated in JS.
<div id="score"></div> It is necessary for #score to assign the width of the variable score , which is equal to 20*2.5 , in percent
It is nece...">
It is necessary to transfer diva width which value is calculated in JS.
<div id="score"></div> It is necessary for #score to assign the width of the variable score , which is equal to 20*2.5 , in percent
To transfer a style value to an element, you need to refer to the element, use the style function and prescribe what exactly you want to change.
Option 1 :
The style is applied directly through the variable names.
Example:
To set the background-color , I will write obj.style.backgroundColor
var score = 20 * 2.5; document.querySelector('#score').style.width = score + '%'; #score { height: 100px; background-color: red; } <div id="score"></div> Option 2 :
Styles are applied via variables from CSS
Example:
To set the background-color , I will directly write obj.style['background-color']
var score = 20 * 2.5; document.querySelector('#score').style['width'] = score + '%'; #score { height: 100px; background-color: red; } <div id="score"></div> style.backgroundColor . 2) It seems to me that the difference is obvious - Yuristyle['background-color'] - for some reason it seems to me that this is not according to the standard ... - Qwertiy ♦Source: https://ru.stackoverflow.com/questions/626334/
All Articles