Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

46
Vistas
Cannot get child element's href value

Being spoiled by jQuery for so long, now I'd like to rewrite this line in vanilla javascript:

let slug = $(this).children().find('.pjt').attr('href');

What I tried (among others) is:

 const goToPage = (e) => {
     var slug = e.target.querySelector(".pjt").attr("href");
    console.log("slug is:", slug);
    //window.location.href = slug;
   };

But I get this error:

Uncaught TypeError: e.target.querySelector(...).attr is not a function

How can I fix this?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It happens to most of us, use getAttribute in Vanilla JS

e.target.querySelector(".pjt").getAttribute('href')
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos