Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!