Resize the window to change background-color - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:width

Description

Resize the window to change background-color

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $(window).resize(function() {/*from  w  w w . ja va 2  s.  c  om*/
    if ($(this).width() < 728) {
      $("body").css("background-color", "yellow");
    } else {
      $("body").css("background-color", "pink");
    }
  });
});
</script>
</head>
<body>

<p>This is a test. This is a test. This is a test.This is a test. This is a test. This is a test.</p>

</body>
</html>

Related Tutorials