0

I would like to change placeholder color by using jQuery because I want to paralyze one input.

All inputs have transparent color after focus via CSS:

:focus::-webkit-input-placeholder { /* Chrome/Opera/Safari */
    color: transparent;
}
:focus::-moz-placeholder { /* Firefox 19+ */
    color: transparent;
}
:focus:-ms-input-placeholder { /* IE 10+ */
    color: transparent;
}
:focus:-moz-placeholder { /* Firefox 18- */
    color: transparent;
}

I tried for example this way, but nothing happened:

inputSelectSubCat.on('mousedown', function() {
   event.preventDefault();
})

But it also paralyze blur and focusin event for this input element.

PS: I read similar topics, but there are not very nice solutions for this problem. I think that must be something more easier then create element.

Dump
  • 237
  • 1
  • 12

1 Answers1

-1

You can use a variable and change its value with style.setProperty method.

For example.

input {
  --placeholder-color: transparent
}
input:focus::-webkit-input-placeholder { /* Chrome/Opera/Safari */
    color: var(--placeholder-color);
}
input:focus::-moz-placeholder { /* Firefox 19+ */
    color: var(--placeholder-color);
}
input:focus:-ms-input-placeholder { /* IE 10+ */
    color: var(--placeholder-color);
}
input:focus:-moz-placeholder { /* Firefox 18- */
    color: var(--placeholder-color);
}
const input = document.querySelector('.input-class');
input.style.setProperty('--placeholder-color', '#333');
Mina
  • 14,386
  • 3
  • 13
  • 26