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

219
Views
Crear lista con hipervínculo (fragmentos de documentos) como cadena de texto

Soy totalmente nuevo en javascript y estoy tratando de crear una lista dinámica en JavaScript que sea un hipervínculo y muestre la cadena de texto de una etiqueta en mi código html que tiene el id = v1. Algo así como un menú a diferentes partes de esa misma página web.

He intentado hacer esto usando fragmentos de documentos ( https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Creating_hyperlinks#document_fragments ) pero no funciona y no tengo ni idea de cómo insertar la cadena de texto del en el "menú".

Aquí está parte de mi código:

 var container = document.getElementById("contentarea"); var header = document.getElementById("v1"); for (i = 0; i < length.header; i++) { $(document.createElement("li")).li; $(document.createElement("a")).link.append(li)( { href: "#v1" }) list.appendChild(li); container.appendChild(list) }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podrías hacer algo como esto

 // div to get the textContent from, replace it with whatever you want const divE = document.getElementById('test'); // our list tag const list = document.getElementById('list'); // looping for (let i = 0; i < 4; i++) { const listEl = document.createElement('li'); // our list element const aTag = document.createElement('a'); // a new <a> tag to append link const linkTag = document.createElement('link'); //new link tag linkTag.href = '#test'; // setting hyperlink aTag.textContent = divE.textContent // setting the textContent for <a> tag aTag.appendChild(linkTag); // appending link to the a tag listEl.appendChild(aTag); // appending a tag to the <li> tag list.appendChild(listEl) // finally appending our list element to the main list }
 <div id="test">Something here</div> <ul id="list"></ul>

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!