Change font size using document.getElementById

I am trying to use document.getElementById to change the font size of some text, but for some reason it does not change and it remains at 200%. What am I doing wrong.

#detail {
font-size: 200%;
}

<div id = "detail"> Hello World <div>

<script type = "text/javascript">

if (true) {
document.getElementById(detail).style["font-size"] = "100%";
}

</script>
+4
source share
1 answer

You should have some quotes for details. and try detail.style.fontSize instead of detail.style ["font-size"]

var detail = document.getElementById("detail");
detail.style.fontSize = "100%";
0
source

Source: https://habr.com/ru/post/1615653/


All Articles