Created
November 25, 2023 11:39
-
-
Save graphoarty/55ca889a5ec407eae74466c0ec12d85e to your computer and use it in GitHub Desktop.
blur select box after selection (even if value is unchanged)
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
let selectDropDownActive = false; | |
let selectDropDownActiveItem = null; | |
$(window).blur(function() { | |
BlurActiveSelectBox(); | |
}) | |
$('select').click(function() { | |
if (selectDropDownActiveItem != this) { | |
selectDropDownActive = false; | |
} | |
if (!selectDropDownActive) { | |
$(document).off('click', BlurActiveSelectBox); | |
setTimeout(() => { | |
$(document).on('click scroll', BlurActiveSelectBox); | |
selectDropDownActive = true; | |
selectDropDownActiveItem = this; | |
}, 100); | |
} | |
}); | |
function BlurActiveSelectBox() { | |
if (selectDropDownActive) { | |
$('select').blur(); | |
$(document).off('click scroll', BlurActiveSelectBox); | |
selectDropDownActive = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment