Skip to content

Instantly share code, notes, and snippets.

@johnfmorton
Last active February 26, 2020 14:05
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 johnfmorton/449b0fc9c29b4a63e564651d5ef8d70d to your computer and use it in GitHub Desktop.
Save johnfmorton/449b0fc9c29b4a63e564651d5ef8d70d to your computer and use it in GitHub Desktop.
Make multiselect fields the full height of number of items with Vanilla JS
// Select the multiselect fields
var mulitSelectFields = document.querySelectorAll('select[multiple]');
// For each field found...
Array.prototype.forEach.call(mulitSelectFields, function(el, i) {
// count how many selection options are present
var itemsInSelect = el.length;
// then set the height with the size attribute to match
el.setAttribute('size', itemsInSelect);
// finally remove the scroll indicator for that field
el.style.overflowY = 'auto';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment