Home  >  Article  >  Web Front-end  >  How to Set CSS Properties on JavaScript Elements: How do I set the width of a select element created with JavaScript to 100px?

How to Set CSS Properties on JavaScript Elements: How do I set the width of a select element created with JavaScript to 100px?

Susan Sarandon
Susan SarandonOriginal
2024-10-31 09:38:01752browse

How to Set CSS Properties on JavaScript Elements: How do I set the width of a select element created with JavaScript to 100px?

CSS Property Settings in JavaScript

Question:

I have created the following elements using JavaScript:

var menu = document.createElement('select');

How do I set the CSS properties of this element, such as width to 100px?

Answer:

You can use element.style to set CSS properties:

var element = document.createElement('select');
element.style.width = "100px";

The above is the detailed content of How to Set CSS Properties on JavaScript Elements: How do I set the width of a select element created with JavaScript to 100px?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn