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

103
Views
How to get data attribute from a DIV and write it to another DIV using jQuery/JS

need to get a data attribute value from a clicked DIV and pass it as data attr for a displaying new DIV:

DIVs to select by click:

<div class="mySlot" data-slot-label="a">A</div>
<div class="mySlot" data-slot-label="b">B</div>
<div class="mySlot" data-slot-label="c">C</div>

The popup DIV that carries over the data-slot value on its as its attr:

<div class="selection" data-slot-label="[The Selected DIV data]"></div>

I'm using this now, but not working:

$('.mySlot').click(function() {
    var mydata = $('.mySlot').data('slot-label');
    $('.selection').data('slot-label',mydata);
});

Cheers

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

$('.mySlot').click(function() {
    var mydata = $(this).attr('data-slot-label');
    $('.selection').attr('data-slot-label',mydata);
});

Just use the attr function to add or retrive the data from an element

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