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

180
Vistas
How can I use JavaScript to print non-visible code?

I am currently using the following script to echo visible text on the screen...

<h1 id="MyText"></h1>

<script>
var el = document.getElementById('MyText');
{ if (italian || french || german)
{ el.innerHTML = (
(italian && 'ciao') ||
(french && 'salut') ||
(german && 'hallo') ); }
else { el.innerHTML = 'hello';}
}
</script>

How should I edit this script, to make it work in case I want it to type a non visible word in the html?

Example:

  • In CSS I have:
#ciao{height:350px;}
#salut{height:10px;}
#hallo{height:3000px;}
  • In my code I want to define my table height basing on these conditions:
<div id="MyText">

The problem is with the above code, this will result in printing a visible text, instead of rather choosing the css id. So how am I supposed to edit the script?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is more idiomatic to add an appropriate class to the div element. [edit] it appears as though you are looking to set the class based on the contents of the div. This is generally a difficult thing to do but here is one approach. Another would be to set a property of the div and then do a :before hack to create a pseudo element with the text of the property.

const langauges = {
  "ciao":"italian",
  "salut":"french",
  "hallo":"german",
  "hello":"english"
}

const updateClass = (el)=>{
  if(langauges[el.innerHTML] != undefined){

    el.className = langauges[el.innerHTML];
  }
}

const onChange = (event)=>{
  const el = event.target;
  updateClass(el);
}

var el = document.getElementById('MyText');
el.addEventListener("input",onChange,false);
updateClass(el);
.italian{height:350px; color:blue;}
.french{height:10px; color:red;}
.german{height:3000px; color:yellow;}
.english{height:3000px; color:purple;}
<h1 id="MyText" contenteditable="true">ciao</h1>

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