Last active
February 26, 2020 14:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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