Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

340
Vistas
How can I go inside this class and print out its name in javascript?

I want reach the area which I have marked blue and print the name of this class (Nnq7C weEfm). I have started from the "main class" and made it into the class called ySN3v like this:

var x = document.getElementsByClassName("SCxLW  o64aR ")[0].children;
var x_in = x[0].children;
var x_in_in = x_in[3].children;
window.alert(x_in_in[0].className);

Which gives me the name of class ySN3v as output. I see no way reaching the blue area and alerting out the name of this class ("Nnq7C weEfm") like this, how can this be done?

If my question is not clear please let me know! :)

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I would give document.querySelector a try, it should make life considerably easier.

const yourDiv = document.querySelector("main.SCxLW.o64aR article div div div");
console.log(yourDiv.className);
<main class="SCxLW  o64aR ">
<div>
<div>
<article>
<div>
<div>
<div class="find this">
</div>
</div>
</div>
</article>
</div>
</div>
</main>

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you want to get the class name of the blue selection and all it's siblings, you can use document.querySelectorAll:

// Get target and all it's siblings
const targetElements = document.querySelectorAll('main article > div > *');

// The a list of unique class names
if (targetElements.length) {
  const classNames = [...new Set(
    [...targetElements].map(({ className }) => className)
  )];

  console.log(classNames);  
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Class Name Example</title>
</head>
<body>
<main>
  <div>
    <header></header>
    <div></div>
    <div></div>
    <div>
      <article>
        <div>
          <div class="target-class"></div>
          <div class="target-class"></div>
          <div class="target-class"></div>
          <div class="another-target-class"></div>
        </div>
      </article>
    </div>
  </div>
</main>
</body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda