jQuery width() get

Introduction

Return the width of the window and document elements

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  .  ja  v  a2 s  .c  o m
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#span1").text($(window).width());
    $("#span2").text($(document).width());
  });
});
</script>
</head>
<body>

<p>The width of this window is <span id="span1">unknown</span> px.</p>
<p>The width of this document is <span id="span2">unknown</span> px.</p>

<button>test</button>

</body>
</html>



PreviousNext

Related