Skip to content

Instantly share code, notes, and snippets.

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 aau8/bfd6ff35a981cc46a894046a491fa927 to your computer and use it in GitHub Desktop.
Save aau8/bfd6ff35a981cc46a894046a491fa927 to your computer and use it in GitHub Desktop.
// Плейсхолдер текстовых полей
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