Javascript examples for CSS Style Property:backgroundColor
Change background color if width is bigger
<html> <head> <style type="text/css"> #mydiv {//from w ww .j a v a 2s .c o m width: 200px; height: 100px; background-color: red; } </style> </head> <body> <div id="mydiv"></div> <script> var mydiv = document.getElementById("mydiv"); var clientRect = mydiv.getBoundingClientRect() var curr_width = clientRect.width || (clientRect.right - clientRect.left); if (curr_width > 100) { mydiv.style.backgroundColor = "blue"; }else{ mydiv.style.backgroundColor = "red"; } </script> </body> </html>