diman91,
<!DOCTYPE HTML>
<html>
<head> </head>
<body>
<div id="container">
<div data-method-click="positive" > click and get positive number</div>
<div data-method-click="negative"> click and get positive negative</div>
</div>
<script>
var cont = document.getElementById("container"),
app = new App,
handlers = {
positive: app.getPositive,
negative: app.getNegative
};
cont.addEventListener("click", onContainerClick);
function onContainerClick (e) {
var val = e.target.getAttribute("data-method-click");
if(val && handlers[val]){
e.target.innerHTML = handlers[val]();
}
}
function App() {
this.getPositive = function () {
return Math.random().toString().slice(2);
};
this.getNegative = function () {
return "-" + Math.random().toString().slice(2);
};
}
</script>
</body>
</html>