Snažím se, aby mé 3 prvky marginLeft
liší se od sebe navzájem, s každým po jedné větší, tím 300px
než předchozí. Jasně, že 'px', což je řetězec je v cestě, ale nevím, jak to překonat.
function render() {
var gElOptions = document.querySelector('.options');
for (var i = 0; i < 3; i++) {
var elOptionBtn = document.createElement('button');
gElOptions.appendChild(elOptionBtn);
elOptionBtn.setAttribute('class', `option-${i}`);
var elOption = document.querySelector(`.option-${i}`);
elOption.style.marginLeft = 1000 + 'px';
// The problematic line:
if (elOption.style.marginLeft === 1000 + 'px') elOption.style.marginLeft -= 300 + 'px';
}
}
<body onload="render()">
<div class="options">
</div>
</body>