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
Set data attribute with native js

How do I set a data attribute with native js so it is picked up with jquery? I have tried using setAttribute, but that only works for the first occasion an any updates aren't picked up:

var iframeHolder = document.getElementById('test');
iframeHolder.setAttribute('data-test', 5);

var $iframe = $('#test');

console.log($iframe.data('test'));

iframeHolder.setAttribute('data-test', 6); // this doesn't seem to update the underlying data attribute

console.log($iframe.data('test'));

iframeHolder.dataset.test = 6;  // neither does this

console.log($iframe.data('test'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="test">inspect to see attribute updates</div>

Please note, I need to use native js as it is in an iframe that doesn't use jquery (but sets the data attribute in the parent window which does use jquery)

about 4 years ago · Juan Pablo Isaza
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