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

224
Views
¿Cómo convertir este jquery en javascript?

He estado usando este código jquery y quiero convertirlo en javascript. Recientemente comencé javascript y tengo un poco de conocimiento en jquery

 <script src="https://code.jquery.com/jquery-2.2.4.js"></script> <script type="text/javascript"> $(document).ready(function () { $(".row a").click(function (e) { e.preventDefault(); $(".imgBox img ").attr("src", $(this).attr("href")); }); }); </script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El equivalente en JavaScript estándar es (agregué algo de HTML para que funcione):

 document.addEventListener('DOMContentLoaded', function () { document.querySelectorAll(".row a").forEach(function(elem) { elem.addEventListener("click", function (e) { e.preventDefault(); document.querySelector(".imgBox img").src = elem.href; }); }); });
 <div class="row"> <a href="https://dummyimage.com/600x120/000/fff">link 1</a> </div> <div class="row"> <a href="https://dummyimage.com/600x120/00f/f88">link 2</a> </div> <div class="imgBox"><img src=""/></div>

about 4 years ago · Juan Pablo Isaza Report

0

Siguiendo las instrucciones de esta hoja de trucos: https://tobiasahlin.com/blog/move-from-jquery-to-vanilla-javascript/

 const ready = (callback) => { if (document.readyState != "loading") callback(); else document.addEventListener("DOMContentLoaded", callback); } ready(() => { /* Do things after DOM has fully loaded */ document.querySelector(".row a").addEventListener("click", (e) => { e.preventDefault(); document.querySelector(".imgBox img ").setAttribute('src', document.querySelector(".imgBox img ").getAttribute('href)); }); });
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!