Last active
May 2, 2022 03:18
-
-
Save aau8/bfd6ff35a981cc46a894046a491fa927 to your computer and use it in GitHub Desktop.
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
// Плейсхолдер текстовых полей | |
labelTextfield() | |
function labelTextfield() { | |
const textfieldElems = document.querySelectorAll('.tf') | |
for (let i = 0; i < textfieldElems.length; i++) { | |
const textfield = textfieldElems[i]; | |
const input = textfield.querySelector('input, textarea') | |
const label = textfield.querySelector('label') | |
if (input.value != '') { | |
label.classList.add('_change-label') | |
} | |
input.addEventListener('focus', e => { | |
label.classList.add('_change-label') | |
}) | |
input.addEventListener('blur', e => { | |
if (input.value === '') { | |
label.classList.remove('_change-label') | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment