title: how to set data-value from javascript
body: <p>Hello I would like to know how I could set the data-value using javascript</p>
  <p>i have this:</p>
  <pre><code>  optionsList.forEach((o) =&gt; {
      o.addEventListener(&quot;click&quot;, () =&gt; {
        selected.innerHTML = o.querySelector(&quot;label&quot;).innerHTML;
        let input = o.querySelector(&quot;input&quot;).value;
        optionsContainer.classList.remove(&quot;active&quot;);
      });
    });
  </code></pre>
  <p>I take the value of my input which is an id
  and I wanted to set the data-value in my selected element</p>
  <p>like this:</p>
  <pre><code>          &lt;div class=&quot;selected&quot; data-value=&quot;1&quot;&gt;
              Select Video Category
            &lt;/div&gt;
  </code></pre>
  <p>I need this value to do an array search</p>
  <p>my input structure:</p>
  <p><a href="https://i.stack.imgur.com/qHRgG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qHRgG.png" alt="enter image description here" /></a></p>