[jquery]width()とheight()で要素の横幅、高さを設定する方法

書式
$(selector).width(xxx).height(xxx);
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#cft").width(450).height(500);
});
});
</script>
<style>
#cft {
height: 120px;
width: 200px;
padding: 10px;
margin: 3px;
border: 1px solid blue;
background-color: lightblue;
}
</style>
</head>
<body>
<div id="cft"></div>
<br>
<button>Resize</button>
</body>
</html>
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#cft").width(450).height(500); }); }); </script> <style> #cft { height: 120px; width: 200px; padding: 10px; margin: 3px; border: 1px solid blue; background-color: lightblue; } </style> </head> <body> <div id="cft"></div> <br> <button>Resize</button> </body> </html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#cft").width(450).height(500);
  });
});
</script>
<style>
#cft {
  height: 120px;
  width: 200px;
  padding: 10px;
  margin: 3px;
  border: 1px solid blue;
  background-color: lightblue;
}
</style>
</head>
<body>

<div id="cft"></div>
<br>

<button>Resize</button>

</body>
</html>

 

jQuery

Posted by arkgame