Compare the width between window and document - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:width

Description

Compare the width between window and document

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(){
    $("button").click(function(){
       $("#span1").text($(window).width());
        $("#span2").text($(document).width());
    });//from w  w w .j av  a  2  s. c o m
});
</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>Return the width of the window and document elements</button>

</body>
</html>

Related Tutorials