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

341
Vistas
how do i check the textcontent inside a button. the if statement isnt recognising the text

Linkedin search result so on the search page i want to only select the buttons with connect on them. the if statement doesnt seem to check if connect is the text content.

var buttons = document.getElementsByClassName('artdeco-button artdeco-button--2 artdeco-button--secondary ember-view')
for (var i = 0; i < buttons.length; i++) {
  console.log(buttons[i].textContent)
  if (buttons[i].textContent == 'Connect') {
    console.log(i)
  }

}
<button aria-label="Invite x to connect" id="ember82" class="artdeco-button artdeco-button--2 artdeco-button--secondary ember-view"><!---->
    <span class="artdeco-button__text">
        Connect
    </span></button>

result Shouldnt the connect have an corresponding i?

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

0

You are performing an exact match on the string "Connect" which fails because the textContent in your example also includes a bunch of whitespace.

You can use String.prototype.trim() to remove it before testing.

var buttons = document.getElementsByClassName('artdeco-button artdeco-button--2 artdeco-button--secondary ember-view')
for (var i = 0; i < buttons.length; i++) {
  console.log(buttons[i].textContent)
  if (buttons[i].textContent.trim() == 'Connect') {
    console.log(i)
  }

}
<button aria-label="Invite x to connect" id="ember82" class="artdeco-button artdeco-button--2 artdeco-button--secondary ember-view"><!---->
    <span class="artdeco-button__text">
        Connect
    </span></button>

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