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

141
Views
Usar la función .each para tomar un valor, luego editar y poner el resultado en otra propiedad de objeto

Estoy tratando de hacer un script que tome la URL de "img src", luego edite y finalmente lo coloque en "a data-title = href", todos ellos en cada "item-foo item-bar item-foo bar" La edición funciona y me sale el link pero luego no puedo hacer el cambio Intento hacer un "each" dentro de otro "each" pero no funciona, luego intento volver con la variable "video" pero solo el sale el ultimo.

Espero poder explicarme bien, lamentablemente el ingles no es mi lengua materna y encima estoy aprendiendo javascript a patadas jaja. Mis saludos y respetos.

Espero poder explicarme bien, lamentablemente el ingles no es mi lengua materna y encima estoy aprendiendo javascript a patadas jaja. Mis saludos y respetos!

 <div class="item-foo item-bar item-foo bar"> <div class="inner-block"> <a data-title="" href="https://example.com/news/16143-chair.htm" title="Chair with rotten legs"> <span class="image"> <img src="https://thumbs.example.com/thumbs/v/i/d/e/o/chair38630.mp4/chair38630.mp4-3.jpg" alt="Chair with rotten legs" /> </span> </a> </div> <div class="item-foo item-bar item-foo bar"> //similar content, diferent URLs </div> <script> jQuery("span.image img").each(function() { direccion = $(this).prop("src"); edit1 = direccion.replace("thumbs", "media"); edit2 = edit1.replace("thumbs", "videos"); index = edit2.indexOf("mp4"); video = edit2.slice(0, index + 3); //console.log("The URL of the video is: " + video); }); </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para encontrar el <a> que contiene, puede usar .closest('a') y luego configurar .attr()

 jQuery("span.image img").each(function() { direccion = $(this).prop("src").replace("thumbs", "media").replace("thumbs", "videos"); $(this).closest('a').attr('href',direccion.slice(0, direccion.indexOf("mp4") + 3)); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="item-foo item-bar item-foo bar"> <div class="inner-block"> <a data-title="" href="https://example.com/news/16143-chair.htm" title="Chair with rotten legs"> Right click and check href <span class="image"> <img src="https://thumbs.example.com/thumbs/v/i/d/e/o/chair38630.mp4/chair38630.mp4-3.jpg" alt="Chair with rotten legs" /> </span> </a> </div> <div class="item-foo item-bar item-foo bar"> <!--similar content, diferent URLs--> </div>

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!