ใช้ ความกว้าง คุณสมบัติใน JavaScript เพื่อกำหนดความกว้างขององค์ประกอบ
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อเรียนรู้วิธีตั้งค่าความกว้างขององค์ประกอบใน JavaScript -
<!DOCTYPE html>
<html>
<body>
<button type="button" id="btn" onclick="display()">
Change height and width
</button>
<script>
function display() {
document.getElementById("btn").style.width = "250px";
document.getElementById("btn").style.height = "250px";
}
</script>
</body>
</html>