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.
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
})
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()'
Just assign function result to property
tdLink2.href = deleteDepartment(id);