I'm

Developer, Designer, Photographer

GET IN TOUCH

  • Buk-gu, Busan, Republic of Korea
  • ungdoli0916@naver.com
  • Kakao ID : Ungdoli
Your message has been sent. Thank you!
(즐거웅코드) 자바스크립트 width 변경하기

· 즐거'웅' 코드 (Source)/HTML & CSS & JAVASCRIPT
2021. 4. 7. 07:55

반응형
JAVASCRIPT
1
2
3
<script>
    document.getElementById('(아이디명)').style.width = (값);
</script>
예제 소스
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<input type="number" id="width_value" placeholder="width 값 입력"/>
<button onclick="test()">width 변경하기</button>
 
<div id="test_obj"></div>
 
<style>
    div {
        width: 200px;
        height: 50px;
        border: 1px solid #bbbbbb;
        background-color: #fbfbfb;
    }
</style>
 
<script>
    function test() {
        var width_value = document.getElementById('width_value').value;
        document.getElementById('test_obj').style.width = width_value;
    }
</script>
구현 예시
반응형