Skip to content
Advertisement

How to create href link to function

I want to create link that send to function:

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

but the “id” parameter was not sent. How can I insert the parameter?

Advertisement

Answer

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()'
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement