Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

71
Visualizações
add href to const value

This title might not be correct, I am new. Basically, I want to apply the href to the name value so that when the element is displayed a can click it like an <a> element. Please help out if you can

const people = [
    {name: 'test1'},
    {name: 'test2'}
];

const list = document.getElementById('list');

function setList(group) {
    clearList();
    for (const person of group) {
        const item = document.createElement('a');
        const text = document.createTextNode(person.name.href);
        item.appendChild(text);
        list.appendChild(item);
    }
    if (group.length === 0 ) {
        setNoResults();
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First of all, I'm not sure if this a valid question for this forum. I would suggest you take some Javascript course and spend some time working on it first. Anyway, what you want to do would be something like this if I understood you correctly:

const people = [
    {name: 'test1', link: 'url1'},
    {name: 'test2', link: 'url2'}
];

const list = document.getElementById('list');

function setList(group) {
    clearList();
    for (const person of group) {
        const item = document.createElement('a');
        const text = document.createTextNode(person.name);
        item.appendChild(text);
        item.setAttribute('href', person.link);
        list.appendChild(item);
    }
    if (group.length === 0 ) {
        setNoResults();
    }
}

You need to use the method "setAttribute" to set the attribute "href" of the "a" (anchor) element so that it gets the main property of a link. And also you need to store it on the people array objects as a new property to be able to access it this way.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda