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

128
Views
HTML value store list of dictionary

I am trying to loop through an array of objects stored in the value-media attribute of my button.

I'm able to get data from value-media and show it, but I can't loop through this data - it treats it like one long string (I'm guessing) and showing "undefined"

var medias = [button.getAttribute('value-media')]
console.log(medias)

$.each(medias, function(index, value) {
  alert(value.id);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<button type="submit" id="editUserBtn" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#editUser" value-userid="34" value-username="CUSTOMER1_TEST2" value-media="[{'id': '50', 'name': 'CUSTOMER1_Windows Notification', 'sendto': ['test@test.com', 'test2@test.com']}, {'id': '51', 'name': 'CUSTOMER1_ALL', 'sendto': ['test@test.com', 'test2@test.com']}]">
  <img src="/static/images/settings_black_24dp.svg" title="Edit user"/>
</button>

Could you help me to make it working? I need to go throught this data and for each dictionary in list take ID :(

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

0

Thank you! It's working now. Here is the solution:

var medias = $(button).data('media')
var mediasJSON = JSON.parse(medias.replace(/\'/g, "\""))
    $.each(mediasJSON, function(index, value) {
        alert(value.name + value.id)
      });

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!