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

138
Vistas
How could I set the value of a div?

I know this is not standard but I want to set the value of a div, like this:

<div id="div" value="1">

document.getElementById('div').value = 2;

to use the value you have to use document.getElementById('div').getAttribute('value') but I cant find any way to set it. thanks in advance!

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

0

You can't set a value to a div. Instead you can try to add a data attribute, like this:

<div id="div" data-value="1">

And if you want to access the data-value from javascript, just use

elem.dataset.{data_attribute_name};, in this case: document.getElementById('div').dataset.value;

Note that you can set multiple data attributes to one element, making it much more versatile than using value.

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