Return the width of the image - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:attr

Description

Return the width of the image

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(){
        console.log("Image width: " + $("img").attr("width"));
    });//w w  w.jav a  2 s . c  o m
});
</script>
</head>
<body>

<img src="http://java2s.com/resources/a.png" alt="message" width="300" height="213"><br>

<button>Return the width of the image</button>

</body>
</html>

Related Tutorials