Naming js nodes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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 Answer
+ 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