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

129
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

Just assign function result to property

tdLink2.href = deleteDepartment(id);
about 4 years ago · Juan Pablo Isaza 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