In the following example code, I attach an onclick
event handler to the span containing the text \"foo\". The handler is an anonymous function that pops up an <
Yes it is possible if you bind events using tag attribute onclick="sayHi()"
directly in template similar like your - this approach similar to frameworks angular/vue/react/etc. You can also use to operate on 'dynamic' html like here. It is not strict unobtrusive js however it is acceptable for small projects
function start() {
mydiv.innerHTML += "bar";
}
function sayHi() {
alert("hi");
}
foo