+ 3
Âżi can change the style of any element / as ?
ÂżHow do change styles within in a script?
2 Answers
+ 1
Javascript offers the possibility, thanks to being an interactive language, to allow to make any type of modification in the original style of a page and in addition without that it is necessary at all to reload the page of the server.
The syntax is as follows:
document.body.style.fontSize="24px"
document.getElementById("id").style.property="value"
The first method allows the style to be applied generally to the document and the second is more specific, when addressed to a block or element defined by an ID identifier.
0
This an example taken from the JS Sololearn Course (DOM&Event, changing element style)
/*Take a look to the entire course , but to provide an answer to your post, see this*/
<div id="demo" style="width:200px">some text</div>
<script>
var x = document.getElementById("demo");
x.style.color = "6600FF";
x.style.width = "100px";
</script>
Every html element's style can be modified by a javascript...