jQuery height() set height via function

Introduction

Use function in height() method

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from  w w w. ja va  2 s.c o m
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("div").height(function(n,c){
      return c+200;
    });
  });
});
</script>
</head>
<body>

<button>Increase height of div with 200 px</button><br><br>

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

</body>
</html>



PreviousNext

Related