

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set the width of an element in JavaScript?
Use the width property in JavaScript to set the width of an element.
Example
You can try to run the following code to learn how to set the width of an element in 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>
- Related Questions & Answers
- How to set the maximum width of an element with JavaScript?
- How to set the minimum width of an element with JavaScript?
- How to set the width of the outline around an element with JavaScript?
- How to set the width of an element's border with JavaScript?
- Set the width of an element to 75% in Bootstrap
- Set the width of an element to 25% in Bootstrap
- Set the width of an element to 100% in Bootstrap
- Set the width of an element to 50% in Bootstrap 4
- Set min-width and max-width of an element using CSS
- How to set width and height of an element using jQuery?
- Set the width of the element in HTML
- How to set the height of an element with JavaScript?
- How to set the margins of an element with JavaScript?
- How to set the padding of an element with JavaScript?
- How to get the width of an element using jQuery?
Advertisements