Set width using value returned from a function - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:width

Description

Set width using value returned from a function

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(){
        $("div").width(function(n, c){
        return c - 200;/*from w w w .  j av  a  2 s  . c  o  m*/
        });
    });
});
</script>
</head>
<body>

<button>Decrease width of div with 200 px.</button><br><br>

<div style="height:100px;border:4px solid;"></div>

</body>
</html>

Related Tutorials