Skip to content
Advertisement

How to append html id with for-loop?

I’m new to JavaScript and HTML. I’m reading my JSON file and appending it to each HTML ID but was wondering if there’s an easier way to do this by using a for-loop?

JavaScript

Advertisement

Answer

Iterating over the changing indicies of 0 to 4 would look to do the trick.

JavaScript

If info.data will have the same number of items in the array as there are vid elements, a more elegant approach would be to give all such vid elements a class in common (such as vid), and then do

JavaScript
Advertisement