We know that if you want to operate CSS in JS, the most important thing is to obtain the style. Here is an article about the most common methods of obtaining styles in JS for your reference.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> div{ color:yellow; } </style> </head> <body> <div style="width:100px;height:100px;background-color:red">This is div</div> </body> </html>
Get it by using the element.style property
<script> var div = document.getElementsByTagName("div")[0]; console.log(div.style.color); //"" console.log(div.style.backgroundColor); //red </script>
The element.style property can only get the inline style, not the style in the