jQuery width() check width

Description

jQuery width() check width

View in separate window

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

<p>Resize the window to change 
background-color.</p>

</body>
</html>



PreviousNext

Related