+ 1

Naming js nodes

when creating new nodes in JavaScript can you give an id or class name?

12th Jan 2024, 12:29 AM
Zvi
Zvi - avatar
1 Odpowiedź
+ 2
you mean DOM elements? yes, you can dynamically assign id and class names to them. const el = document.createElement('div'); el.classList.add('class-name-here'); el.id = 'id-name-here'
12th Jan 2024, 1:50 AM
Bob_Li
Bob_Li - avatar