Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Created April 24, 2024 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziadoz/1feb0ab209527744543ffec9e02ec50c to your computer and use it in GitHub Desktop.
Save ziadoz/1feb0ab209527744543ffec9e02ec50c to your computer and use it in GitHub Desktop.
DOM Properties
<div id="app"></div>
<script>
const option = document.createElement('option');
option.value = 'Foo Bar';
const datalist = document.createElement('datalist');
datalist.id = 'foo-bar';
datalist.appendChild(option);
const input = document.createElement('input');
input.type = 'text';
input.list = 'foo-bar'; // Doesn't work...
input.setAttribute('list', 'foo-bar'); // Does work...
const app = document.getElementById('app');
app.appendChild(input);
app.appendChild(datalist);
</script>
<!-- https://jakearchibald.com/2024/attributes-vs-properties/ -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment