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

110
Vistas
Select Every One not just first

I'm working on a custom java script variable for tag manager to track the navigation of my page. The script is only working for the very first element of the kind because of document.queryselect. document.queryselectAll is naturally not solving the problem. It would be great if you could help me:

function(){
   var elem = {{Click Element}};
   var menu = document.querySelector("ul.nav.meta-nav.justify-content-end");
   if(menu.contains(elem)){
     return "nav_header";
   };
var menu = document.querySelector("div.product-item");
   if(menu.contains(elem)){
     return "itemlist";
   };
var menu = document.querySelector("a.btn");
   if(menu.contains(elem)){
     return "cta_button";
   };
var menu = document.querySelector("footer.footer*");
   if(menu.contains(elem)){
     return "footer";
    }
   return "other";
}
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Element.querySelectorAll() returns a NodeList. It's like an array. So a typical usage would be:

var elem = {{Click Element}};
document.querySelectorAll(selector).forEach(function(el) {
  if (el.contains(elem)) {
    return el.getAttribute("data-something");
  }
})
about 4 years ago · Santiago Trujillo Denunciar

0

function(){
  var elem = {{Click Element}};
  var type = "other"

  var selectors = {
    "ul.nav.meta-nav.justify-content-end" : "nav_header",
    "div.product-item" : "itemlist",
    "a.btn" : "cta_button",
    "footer.footer *"   : "footer"
  }

  for (const [key, value] of Object.entries(selectors)) {
    var domMenu = document.querySelector(key)
    if(domMenu && domMenu.contains(elem)){
       type = value
     };
  }

  return type;
}

Can not test from my end but it might work.

Just make sure the selectors is good and the click element should not fall into more than one selectors.

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