GetElementBy id using variable? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 7

GetElementBy id using variable?

pos = "bottom"; document.getelementbyid("player").style.pos Pos has to be a variable can anyone help me please?

2nd Apr 2018, 5:55 PM
Arne Van Kerckvoorde
Arne Van Kerckvoorde - avatar
2 Réponses
+ 11
var player = document.getElementById("player"); player.style[pos] = .......
2nd Apr 2018, 6:12 PM
Burey
Burey - avatar
+ 1
...'player').style.position=pos;
2nd Apr 2018, 10:28 PM
wenz
wenz - avatar