---
title: "Change background color of window when window is resized"  
description: "Change background color of window when window is resized"  
author: "Ethan Karla"  
published: 2021-07-28  
updated: 2023-11-27  
canonical: https://www.mindstick.com/forum/156653/change-background-color-of-window-when-window-is-resized  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# Change background color of window when window is resized

How to change [background color](https://www.mindstick.com/forum/12937/how-to-style-togglebutton-so-that-the-background-color-is-white) of [window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript) when window is resized?

## Replies

### Reply by Aryan Kumar

If you want to check the [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp) [color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp) of the window when it's resized and do something based on that in jQuery, you can use the **$(window).resize()** event. Here's an example:

```plaintext
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Check Background Color on Window Resize</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      background-color: #ffffff; /* Set your default background color */
    }
  </style>
  <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>

<script>
  $(document).ready(function () {
    // Initial check on document ready
    checkBackgroundColor();

    // Check on window resize
    $(window).resize(function () {
      checkBackgroundColor();
    });

    function checkBackgroundColor() {
      // Get the background color of the body element
      var bgColor = $('body').css('background-color');

      // Display the background color in the console (you can replace this with your logic)
      console.log('Background Color:', bgColor);

      // Example: Change something based on the background color
      if (bgColor === 'rgb(255, 255, 255)') {
        // Change something for white background
        console.log('White background detected.');
      } else {
        // Change something for non-white background
        console.log('Non-white background detected.');
      }
    }
  });
</script>

</body>
</html>
```

In this example:

- The initial background color is set using CSS.
- The **$(window).resize()** event is used to trigger the **checkBackgroundColor** function whenever the window is resized.
- The **checkBackgroundColor** function gets the background color of the body and logs it to the console. You can replace the console.log statements with your desired logic based on the background color.

Remember to adjust the logic inside the **checkBackgroundColor** function according to your specific requirements.


---

Original Source: https://www.mindstick.com/forum/156653/change-background-color-of-window-when-window-is-resized

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
