Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda