the old way is
<a onclick="myfunction('mystring')">1</a>
but this has alot of limits.
I think the most correct way to pass strings (variables) to javascript is this:
a new way to interact with clickevents is to add eventlisteners in your javascript code.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
window.onload=function(){
var handler=function(e){//define your function (click handler)
console.log(e,this);// contains the event details and the clicked element details
}
var a=document.getElementsByTagName('a')[0]; // with this line i get the first a
a.addEventListener('click',handler,false);// add the click lisstener
}
</script>
</head>
<body>
<a>1</a>
</body>
</html>
so now u just have to find out where is the best place to storeyour string in the <a>1</a>
in the title
<a title="mystring">1</a>
to get this info in your handler u just have to write this.title
to get the string
inside the anchor
<a>mystring</a>
to get this info in your handler u just have to write this.innerText
to get the string
there is also a new way to store information inside elements called dataset
<a data-string="mystring">1</a>
to get this info in your handler u just have to write this.dataset['mystring']
to get the string
like i sayd it passes also the event details... inside that u can find also the element.
most common way is target:
e.target.title
e.target.innerText
e.target.dataset['string'];
using this addEventListeners allows you to add mutiple click events ... or at the other side it allows you to handle multiple elements with one click.