EN
JavaScript - style element in React way with inline style property
3 points
In this short article, we would like to show how in JavaScript style elements in React way - style elements with object.

Practical example:
xxxxxxxxxx
1
2
<html>
3
<head>
4
<script>
5
6
function styleElement(element, styles) {
7
for (var key in styles) {
8
element.style[key] = styles[key];
9
}
10
}
11
12
</script>
13
</head>
14
<body>
15
<div id="element">Element body...</div>
16
<script>
17
18
var element = document.querySelector('#element');
19
20
styleElement(element, {
21
padding: '5px 10px 20px 30px',
22
border: '5px dashed red',
23
background: 'yellow',
24
color: 'blue'
25
});
26
27
</script>
28
</body>
29
</html>