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

103
Views
Javascipt Intentando obtener contenido de <a> tage

He estado tratando de obtener todos los detalles de una serie de etiquetas en una página HTML. Puedo obtener el ID y el texto, pero todos los demás valores se me escapan. El HTML tiene este aspecto.

 <a class="cuenta" codigo="1.1.1.1" nombre="Caja" data-placement="right" data-popover-content="#popover_content_wrapper" data-title="Menú Opciones" data-trigger="focus" desc="1.1.1.1 Caja" href="javascript:void(0);" id="619060" padre="619059" rel="" style="color:black;">1.1.1.1 Caja</a>

1.1.1.1 Caja

El código que funciona

 var x = document.querySelectorAll("a"); var myarray = [] for (var i=0; i<x.length; i++){ var allcontent = x[i].elements var nametext = x[i].textContent; var cleantext = nametext.replace(/\s+/g, ' ').trim(); var classtype = x[i].class; var nombretxt = x[i].nombre; var idno = x[i].id; var padreno = x[i].padre; myarray.push([idno,nametext]); }; function make_table() { var table = '<table><thead><th>idno</th><th>nametext</th></thead><tbody>'; for (var i=0; i<myarray.length; i++) { table += '<tr><td>'+ myarray[i][0] + '</td><td>'+myarray[i][1]+'</td></tr>'; }; var w = window.open(""); w.document.write(table); } make_table()

También necesito obtener los valores de class= codigo= padre= nombre= en la matriz pero experimentando con var nombretxt = x[i].nombre; y similar no devuelve un valor

Muchas gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  • Usando la propiedad getAttribute() de DOM

 const aTag = document.querySelector("a"); let padreno = aTag.getAttribute("padre"); let classtype = aTag.getAttribute("class"); let nombre = aTag.getAttribute("nombre"); console.log({ padreno, classtype, nombre }); //{padreno: '619059', classtype: 'cuenta', nombre: 'Caja'}
 <a class="cuenta" codigo="1.1.1.1" nombre="Caja" data-placement="right" data-popover-content="#popover_content_wrapper" data-title="Menú Opciones" data-trigger="focus" desc="1.1.1.1 Caja" href="javascript:void(0);" id="619060" padre="619059" rel="" style="color: black" >1.1.1.1 Caja</a >

about 4 years ago · Juan Pablo Isaza 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!