title: Function only working after edit and refresh in Vue?
body: <p>My function in Vue seems to only work after intentionally causing an error and then refreshing the page. The code works fine it's just the initialization that's isn't working.
  Can anyone help?</p>
  <p>Brief explanation:</p>
  <p>When the user hits the button, a function is called by the name of <code>provjeriOdgovore</code>.
  The function looks for all the elements with the class name <code>answer</code> (the input fields), and then iterates, checking if the value of the input is contained inside of the variable <code>odgovori</code>. If it is, the program appends the class <code>green-color</code> to the classList of <code>answer</code>, if it isn't, the same thing happens but instead of <code>green-color</code>, it's <code>red-color</code></p>
  <p>Code in question:</p>
  <p>HTML part:</p>
  <pre><code>&lt;input class=&quot;answer&quot; type=&quot;text&quot;&gt;
  &lt;input class=&quot;answer&quot; type=&quot;text&quot;&gt;
  &lt;input class=&quot;answer&quot; type=&quot;text&quot;&gt;
  
  &lt;button :onclick=&quot;provjeriOdgovore()&quot;&gt;Provjeri&lt;/button&gt;
  </code></pre>
  <p>Javascript part:</p>
  <pre><code>const odgovori = [[long array of strings], [long array of strings], [long array of strings]]
  
  export default {
    data() {
      return {
          provjeriOdgovore: () =&gt; {
            let questionDiv = document.getElementsByClassName(&quot;answer&quot;)
            for (let i = 0; i &lt; questionDiv.length; i++) {
                let userInput = questionDiv[i].value.toLowerCase();
                questionDiv[i].classList.add(&quot;color-white&quot;)
                if (odgovori[i].includes(userInput)) {
                    console.log(&quot;tocno&quot;, questionDiv[i])
                    questionDiv[i].classList.add(&quot;green-color&quot;);
                    if (questionDiv[i].classList.length &gt; 2) {
                        questionDiv[i].classList.remove(&quot;red-color&quot;);
                    }
                } else {
                    console.log(&quot;netocno&quot; ,questionDiv[i])
                    questionDiv[i].classList.add(&quot;red-color&quot;);
                    if (questionDiv[i].classList.length &gt; 2) {
                        questionDiv[i].classList.remove(&quot;green-color&quot;);
                    }
                } 
            }
        }
      }
    }
  }
  </code></pre>