Jump to content
Larry Ullman's Book Forums

Recommended Posts

These scripts are not working .. I`ve crossed check them from Source code also. Please check.



var U = {
$: function(id){
'use strict';
if(typeof id == 'string'){
return document.getElementById(id);
} // inner IF
}, // $() function

setText: function (id,message){
'use strict';
if((typeof id == 'string') && 
(typeof message == 'string')){
var output = this.$(id);
if (!output)return false;
if(output.textContent !== undefined){
output.textContent = message;
}// second inner IF
else { output.innerText = message;}
return true;
}// inner IF

},// SetText Function

addEvent : function(obj,type,fn){
'use strict';
if(obj && obj.addEventListener){
}//inner IF
else if (obj && obj.attachEvent){
obj.attachEvent('on' + type, fn);
}// Else IF
},// addEvent Property

removeEvent : function(obj,type,fn){
'use strict';
if(obj && obj.removeEventListener){
}// inner IF
else if(obj && obj.detachEvent){
obj.detachEvent('on' + type, fn);
}// Else IF
}// RemoveEvent




function updateDuration(){

'use strict';

var now = new Date();
var message = 'It has been ' + now.getDate();
message += ' seconds since epoch.(Mouseover to Update)';

U.setText('output', message);

}// Update Duration Function Ends Here

window.onload = function(){

'use strict';
U.addEvent(U.$('output'), 'mouseover', updateDuration);


}; // Onload Function


<!doctype html>
<meta charset="utf-8">
<title>Mouse Events - Javascript</title>


<div id="output"></div>

<script src="utility.js"></script>
<script src="epoch.js"></script>


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...