Can I pass a string argument to an onclick javascript function?

Solution 1:

You can do it in 2 ways. You can either call the function from the element itself like:

<a href="javascript:void;" onclick="myFunction ('string')" id="druck">

Or you can use a data-* attribute;

<a href="javascript:void;" data-string="my string" id="druck">

And inside js,

b.onclick = (event) => {
  let myString = event.currentTarget.dataset.string;
  //Code
}

(https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset)