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

128
Views
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 answers
Answer question

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 Report

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 Report

0

Just assign function result to property

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