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

351
Views
¿Cómo puedo obtener el valor de los datos-* jquery
<img src="lazy.png" data-kjkjsdfkjf="realurl.png"> <img src="lazy.png" data-3a4244454a="realurl.png"> <img src="lazy.png" data-32423fasf="realurl.png"> <img src="lazy.png" data-dasflkj="realurl.png">

¿Cómo puedo cambiar todos los datos-* a src?

 $("img").lazyload({ onError: function (element) { $(element).attr('src', jQuery(element).attr('data-*')); } });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Esto funciona en JavaScript vainilla:

 <img src="lazy.png" data-kjkjsdfkjf="realurl.png"> <img src="lazy.png" data-3a4244454a="realurl.png"> <img src="lazy.png" data-32423fasf="realurl.png"> <img src="lazy.png" data-dasflkj="realurl.png"> <script> // gets all images in document (you can do this with only a specific div instead of document if needed) let images = document.getElementsByTagName("img"); // loops through images for(let i = 0; i < images.length; i++){ // the current image in the loop let image = images[i]; // gets the name of the first property in the dataset let dataName = Object.keys(image.dataset)[0]; // gets actual value in dataset from the name we found above let realUrl = image.dataset[dataName]; // sets the new src image.src = realUrl; } </script>

about 4 years ago · Juan Pablo Isaza Report

0

Por favor intenta lo siguiente

 const values = []; document.querySelectorAll('img').forEach((img) => { const value = img.getAttributeNames()[1].split('-')[1]; values.push(value); }); console.log(values);
 <img src="lazy.png" data-kjkjsdfkjf="realurl.png" /> <img src="lazy.png" data-3a4244454a="realurl.png" /> <img src="lazy.png" data-32423fasf="realurl.png" /> <img src="lazy.png" data-dasflkj="realurl.png" />

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!