Home > Web Front-end > JS Tutorial > body text

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
Release: 2024-10-31 09:38:01
Original
751 people have browsed it

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');
Copy after login

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";
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template