Javascript examples for jQuery Method and Property:width
Resize the window to change background-color
<!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>