Skip to content

Instantly share code, notes, and snippets.

@softiconic
Last active December 2, 2023 19:01
Show Gist options
  • Save softiconic/f787f2802b2122b089dd3fe49641009c to your computer and use it in GitHub Desktop.
Save softiconic/f787f2802b2122b089dd3fe49641009c to your computer and use it in GitHub Desktop.
Style the color of the placeholder or first option in a select dropdown.
<script>
$(function($) {
/*function for placeholder select*/
function selectPlaceholder(selectID){
var selected = $(selectID + ' option:selected');
var val = selected.val();
$(selectID + ' option' ).css('color', '#2c2c2c');
selected.css('color', '#AEC3ED');
if (val == "") {
$(selectID).css('color', '#AEC3ED');
};
$(selectID).change(function(){
var val = $(selectID + ' option:selected' ).val();
if (val == "") {
$(selectID).css('color', '#AEC3ED');
}else{
$(selectID).css('color', '#2c2c2c');
};
});
};
selectPlaceholder('select');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment