I am new to JavaScript, My question is when I try this JS in chrome browser console it works, But in my JS file it's not working
I attached the code, For HTML design I used google MDL, For JS I used Google Closure
HTML :
<HTML>
<head>
<script src="../closure-library/closure/goog/base.js"></script>
<script src="../js/add.js"></script>
<script src="../js/material.js"></script>
<link rel="stylesheet" href="../css/material.css">
<link rel="stylesheet" href="../css/test_add.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<div>
<button id="add" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect">
<i class="material-icons">add</i>
</button>
</div>
</body>
</HTML>
JS:
goog.provide('sample.add');
goog.require('goog.dom');
goog.require('goog.events');
sample.add = function() {
self = this;
};
goog.inherits(sample.add, goog.base);
sample.add.prototype.bindEvent = function() {
goog.events.listen(goog.dom.getElement('add'),
goog.events.EventType.CLICK, function(e) {
alert("HAPPY");
});
};
What is wrong with this code
- When I try without
goog.provide
andgoog.require
its show error to all - When I use this there is no reaction to the click event
- Is there any other best resource to see online
Kindly help me