Home >Web Front-end >JS Tutorial >How to Style Dynamically Created Elements in JavaScript?
Q: How can I set CSS properties for elements I've created dynamically in JavaScript?
A: To set CSS properties for dynamically created elements, you can use the element.style property. Here's how:
<code class="javascript">var menu = document.createElement('select');</code>
<code class="javascript">menu.style.width = "100px";</code>
In this example, the width property is set to "100px" for the newly created menu element. You can set any valid CSS property in this manner.
The above is the detailed content of How to Style Dynamically Created Elements in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!