可以使用JavaScript创建具有特定类名称的新的HTML元素吗?
我正在尝试创建具有特定类名称的HTML元素,因此当内容在DOM上时,CSS样式可以应用于它。这可能吗?
I am trying to create an HTML element with a specific class name so when the content is on the DOM the CSS styles can be applied to it. It this possible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在其中创建元素并插入类。
前任:
Just create the element and insert class inside it.
Ex:
正如@mina所说,您可以使用
element.Classlist.add(“ myClass”)
。as @Mina said , you can use the
element.classList.add("myClass")
.