Assignment of ID and class in JS [closed]

1

I'm new to programming, I have a problem, and I have to create a menu from JS without touching the HTML, more or less I've finished it, but I need to add an ID and a class to each tag to be able to manipulate them later Can someone tell me a JS method to do it? Thanks in advance ; )

    
asked by Fausto Jeje 21.04.2018 в 21:18
source

1 answer

0

The SetAttribute method can help you, what you should do is look for the element that you will put the attribute and as the first parameter you must put what attribute is, and as second the value

EXAMPLE:

Elemento.setAttribute('class','ElnombreDeMiClase')

EXAMPLE2:

Elemento.setAttribute('id', 'NombreDeMiId')

In these cases Element is taking the role of a variable thinks that the Element is something like this

var Elemento = document.getElementById('div')
    
answered by 21.04.2018 / 21:34
source