0

Мне нужно в инпуте у которого класс .time-spending-input менять background-image когда в нём появляется текст. Как

let allInput = document.querySelectorAll('input');

function removeDone(input){
       for(const input of allInput){
        if(input.value ==" "){
            form.querySelectorAll(".time-spending-input").style.backgroundImage = "url(image/check.svg)";
        }
    }
}

removeDone(input)
3
  • Если .time-spending-input один, то используйте document.querySelector, т.к. document.querySelectorAll возвращает коллекцию и надо проходиться по ней циклом, что бы что от поменять в элементах
    – SwaD
    24 янв в 15:07
  • @SwaD .time-spending-input их 4 24 янв в 15:14
  • Тогда ваш код должен выглядеть как то так: .querySelectorAll(".time-spending-input").forEach(item => item.style.backgroundImage = "url(image/check.svg)")
    – SwaD
    24 янв в 15:24

1 ответ 1

3

Мне нужно в инпуте у которого класс .time-spending-input менять background-image когда в нём появляется текст

.time-spending-input{width: 100%;
background-image: linear-gradient(90deg, green, blue)}

.time-spending-input::placeholder{ opacity: 1;
background-image: linear-gradient(90deg, yellow, red)}
<input placeholder='а обязательно JavaScript юзать? может и так сойдёт? :3'
class='time-spending-input'>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.