DomTemplate Example

Here we are registering an onClick handler for the div. Any type of event handler can be registered. This is particularly handy when this is used as the data to the template engine. We make sure that the context of the function is the object that called it, so you have access to all your data: i.e. DomTemplate automatically binds function calls in the way we wish JavaScript had done from day one

HTML

<script src="https://github.com/PAEz/domtemplate/raw/master/lib/domtemplate.js"></script>
<div id="ex5" onclick="${clickHandler}">${name}</div>

JavaScript

function Person(name) {
    this.name = name;
}
Person.prototype = {
    display: function() {
        template('ex5', this);
    },
    clickHandler: function(ev) {
        console.log('You clicked on ' + this.name);
    }
};
var joe = new Person('Joe');
joe.display();