Search code examples
javascripthtml-input

Change value of data-list inside an Input tag


I want to change the value of the 'data-list' attribute here :

<input id="Searchbar" data-list="Javascript,Css,Test" data-multiple/>

I tried :

Document.getElementById('Searchbar').XXXXX

All this stuff but I can't find the right way to do it.

Any suggestions?


Solution

  • The document is case sensitive. Try:

    document.getElementById('Searchbar').XXXXX
    

    And to set the data-list attribute, you need to do:

    document.getElementById('Searchbar').setAttribute("data-list", "new,list");