Decrease image width by 50px - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:attr

Description

Decrease image width by 50px

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(){
        $("img").attr("width",function(n, v){
            return v - 50;/*from   ww  w  .j  a v a2s  .  co m*/
        });
    });
});
</script>
</head>
<body>

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

<button>test</button>

</body>
</html>

Related Tutorials