0

Made a list in html and gave every option a value of numbers (0,1,2,...) and gave all the options the same class 'op' and then I want to save this values in an array in javascript but my code doesn't seem to work.

output should be [0,1,2,3,...] instead nothing happens

    let valuesfromhtml = document.getElementsByClassName('op').value;
        function test(value){ for (i=0 ; i < valuesfromhtml ; i++){
              let valuesofnames = [];
              valuesofnames.push(valuesfromhtml);
    console.log(valuesofnames)}
    }
Marco Maher
  • 351
  • 1
  • 9
  • 1
    document.getElementsByClassName('op') is a collection of DOM elements ; it would be easier if you provide a mini example code to illustrate your question please read https://stackoverflow.com/help/minimal-reproducible-example – Mister Jojo May 15 '20 at 17:49
  • ^ The important part of what Jojo just said, is that a collection of DOM elements does not have a `.value`. You would have to loop over them to get each value – Taplar May 15 '20 at 17:50
  • I used the for loop and it didn't work – Marco Maher May 15 '20 at 21:06
  • what is dom elements please – Marco Maher May 15 '20 at 21:06

0 Answers0