I'm trying to perform an anonymous function with a this-type argument, with the aim that an element of DOM can occupy it.
javascript: (this is dynamically created at run time)
const example = function(this) { return this }
html:
<button onclick="example(this)" ><button>
result:
Uncaught SyntaxError: Unexpected token 'this'
how can I do it?, thanks!
As mentioned in the comments, this is a special keyword in JavaScript; when you call an object method, this contains the object that the method was called through.
Just use another variable name.
const example = function(el) { console.log(el.innerText); };
<button onclick="example(this)" >Click me</button>