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

130
Visualizações
How create href link to function js?

I want to create link that send to function:

    tdLink2.innerText="Delete";
    tdLink2.href="javascript:deleteDepartment(id)"

but the "id" parameters was not sent. Who I can do this with the parameters? (Javascript) Thank you.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

ID is not parsed in your string

EITHER (Don't forget the extra quotes if ID is a string

tdLink2.href="javascript:deleteDepartment('"+id+"')" 

alternative with template literals

tdLink2.href=`javascript:deleteDepartment('${id}')`; 

I would personally keep DELETE far away from a href

This is better

tdLink2.href="#"
tdLink2.addEventListener("click",function(e){
  e.preventDefault(); /stop the link
  deleteDepartment(id); // id is some global variable
})

EVEN better is to do

tdLink2.href="#";
td.dataset.id = id; // assign to a data attribute
tdLink2.addEventListener("click",function(e){
  e.preventDefault(); // stop the link
  deleteDepartment(this.dataset.id); // pass the data attribute
})
about 4 years ago · Juan Pablo Isaza Relatório

0

If id is already a defined variable then you can do like this:

tdLink2.href=`javascript:deleteDepartment(${id})`

You can do this if it is of type string.

Otherwise you can go for this:

function f(){
  deleteDepartment(id)
}
tdLink2.href='javascript:f()'
about 4 years ago · Juan Pablo Isaza Relatório

0

Just assign function result to property

tdLink2.href = deleteDepartment(id);
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