ใช้คุณสมบัติ width ใน 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>