Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
How do you assign a placeholder color to an id attribute?

I am working on a student project in Google Apps Script. The goal at present is to change the color of a placeholder in a textarea with a button push. My current concept is to assign the placeholder to an id attribute. Is there a way to change the placeholder's color using an id?

var backgroundColors = ["white", "blue", "green", "red", "black"];
var buttonIndex = [0, 0];

$("document").ready(function() {
  console.log("Begin Kernsky ...");
  $("#button-nav-left-bottom, #button-nav-right-top, #button-nav-right-bottom, #button-nav-right-top").on("click", function(evt) {
    console.log("Clicked: ", this);
    var reset = $(this).data('btn');
    console.log("buttonIndex[" + reset + "] = (buttonIndex[" + reset + "] +1) % 5 ; ",
      "buttonIndex[" + reset + "] = " + (buttonIndex[reset] + 1) % 5 + ";");
    $(this).removeClass(backgroundColors[buttonIndex[reset]]);
    buttonIndex[reset] = (buttonIndex[reset] + 1) % 5;
    // Left button
    if (reset == 0) {
      $("#button-nav-left-bottom, #button-nav-right-top, #textarea-left").css("background-color", backgroundColors[buttonIndex[reset]]);
      if (buttonIndex[1] == buttonIndex[reset]) {
        console.log("Left-bottom-right-top-button changes the background-color to the next value.");
        buttonIndex[reset] = (buttonIndex[reset]) % 5;
      }
    }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can achieve it using CSS Variables.

On click of the button, just set the color value in the variable. Color names/codes can be used.

var backgroundColors = ["pink", "blue", "green", "red", "black", "yellow", "blueviolet", "brown"];

function change(elem)
{
  var btn = document.getElementById("btn");
  var randomIndex = new Date().getTime() % backgroundColors.length;
  btn.style.setProperty("--buttoncolor", backgroundColors[randomIndex])
}
.color_placeholder::placeholder{
  color: var(--buttoncolor);
}
<input id="btn" placeholder="Some text" class="color_placeholder">
<button onclick="change(this)">Change color</button>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda