.width()メソッドと.Height()メソッド


.width()メソッドと.height()メソッドは、選択した要素の幅または高さを返したり設定したりします..width() 메소드와 .height() 메소드로 박스크기 키우고 줄이기 예제

<body>
	<h1>.width() 메소드와 .height() 메소드</h1>
	<button id="size">크기</button>
	<button id="size-up">줄이기</button>
  	<button id="size-down">키우기</button><br><br>
	<div id="box" style="width: 400px; height: 200px; background-color: yellow"></div>
	<p id="text"></p>
	
    <script>
		$(function() {
			$("#size").on("click", function() {
				var size = "너비는 " + $("#box").width() + "px이고, 높이는 "
					+ $("#box").height() + "px입니다.<br>";
				$("#text").html(size);
			});
			$("#size-up").on("click", function() {
				w = $("#box").width();
				h = $("#box").height();
				$("#box").width(w/2).height(h/2);

				var size = "너비는 " + $("#box").width() + "px이고, 높이는 "
					+ $("#box").height() + "px로 변경되었습니다.<br>";
				$("#text").html(size);
			});
            $("#size-down").on("click", function() {
                  w = $("#box").width();
                  h = $("#box").height();
                  $("#box").width(w*2).height(h*2);

                  var size = "너비는 " + $("#box").width() + "px이고, 높이는 "
                      + $("#box").height() + "px로 변경되었습니다.<br>";
                  $("#text").html(size);
              });
		});
	</script>
</body>