Javascript examples for jQuery Method and Property:attr
Return the width of the image
<!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>