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

160
Views
¿Por qué para... de paradas?

Tengo una pieza de HTML:

 <a name="list">the list</a> <ul> <li><a href="http://google.com">http://google.com</a></li> <li><a href="/tutorial">/tutorial.html</a></li> <li><a href="local/path">local/path</a></li> <li><a href="ftp://ftp.com/my.zip">ftp://ftp.com/my.zip</a></li> <li><a href="http://nodejs.org">http://nodejs.org</a></li> <li><a href="http://internal.com/test">http://internal.com/test</a></li> </ul>

y una pieza de JS:

 let links = document.querySelectorAll('a'); for (let link of links) { let href = link.getAttribute('href'); alert(href.includes("://"))

La pregunta es por qué el JS anterior no funciona (debería mostrar verdadero/falso), pero funciona si agrego una condición if:

 let links = document.querySelectorAll('a'); for (let link of links) { let href = link.getAttribute('href'); if (!href) continue; alert(href.includes("://"))
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

No funciona cuando no agregó la declaración if porque hay un caso en que href devuelve null para la lista de enlaces que está intentando. Para su información, comparto el mensaje de console.log cuando no funciona.

 VM260:4 Uncaught TypeError: Cannot read properties of null (reading 'includes') at <anonymous>:4:14

Si agrega la instrucción if , la includes no se ejecuta en el fragmento de código. Espero que te quede claro.

about 4 years ago · Santiago Gelvez 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!