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

197
Visualizações
How to check if the given string is a valid 'PropertyName' and 'PropertyValue' for the style attribute of an HTML element?

I would like to dynamically add/edit a property of the style attribute based on the user input. The user can give the Property Name and Property Value as a string. I would need to validate, if the given string is a valid property name/property value for the style attribute of an HTML element before applying.

Is there any way to achieve the above validation?

Is there any javascript function that can validate the given string for valid property name/property value or function that returns all valid properties/values for a particular property of the style attribute

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

0

The idea is applying the style and checking for its existence. This function can use some improvements but it works or at least demonstrates the concept.

function is_valid_css_prop(prop, value) {
  var div = document.createElement("div");
  document.body.appendChild(div)
  div.style[prop] = value;
  var obj = getComputedStyle(div);

  var found = false;
  for (var key in obj) {
    if (key == prop && value == obj[key]) {
      found = true;
      break;
    }
  }
  document.body.removeChild(div)
  return found;
}


console.log(is_valid_css_prop("position", "above"));
console.log(is_valid_css_prop("position", "absolute"));

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