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

122
Views
¿Cómo obtengo la identificación presente en el enlace usando jQuery?

Estoy llamando datos de una API de película usando jquery y tiene un punto final donde puedo llamar a un programa en particular con una identificación. La página de inicio muestra las películas y hacer clic en ellas debería llamar a otro punto final de la API. A continuación se muestra mi código:

 $(function (){ let $movies = $('#showList') $.ajax({ method:'GET', url:'http://api.tvmaze.com/shows', success: function(movies){ $('#show').hide() $('#showList').removeAttr('hidden'); $.each(movies, function(i,movie){ $movies.append('<li class="list"><a id="ss" href="'+ movie._links.self.href+'">'+ movie.name +'</a></li>') }) } }) }) $('body').on('click','.list a',function(event){ event.preventDefault(); $('#showList').hide(); $('#show').empty() let currentId = event.target.id; console.log(currentId) $.ajax({ method:'GET', url:'http://api.tvmaze.com/shows/'+currentId, success: function(movies){ $('#show').append('<h1>'+ movies.name +'</h1>') } }) $('#show').show();

HTML:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>TV Shows</title> </head> <body> <h1>TV Shows</h1> <div id="show" hidden></div> <ul id="showList" hidden></ul> <form id="searchForm"> <input type="text" id="search_term"> <label for="text">Search</label> <button>Submit</button> </form> <a id="homelink" href="/" hidden>Back to All Shows</a> <footer>Swayam Shah, 10471353</footer> <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script> <script src="/public/js/index.js"></script> </body> </html>

¿Cómo obtengo esta identificación cuando hago clic en el enlace de películas? El archivo console.log se muestra vacío.

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

0

no ha mencionado el atributo de identificación en su etiqueta de anclaje.

 $movies.append('<li class="list"><a href="'+ movie._links.self.href+'">'+ movie.name +'</a></li>')
about 4 years ago · Juan Pablo Isaza Report

0

Tuve que reemplazar la URL con solo el ID actual

about 4 years ago · Juan Pablo Isaza Report

0

Usar "esto" funciona para mí.

 $("a").click(function() { console.log($(this).attr("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!