jQuery width() set via function

Introduction

Decrease width of div with 200 px.

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  www.j  a v a 2s.  co  m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("div").width(function(n, c){
      return c - 200;
    });
  });
});
</script>
</head>
<body>

<button>test</button><br><br>

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

</body>
</html>



PreviousNext

Related