This will create a nice JS clock. You can change the color of it too.
1. Insert this into the of an HTML document"
| <script type="text/javascript"> function showtime(){ if (!document.all& &!document.getElementById) return thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2 var Digital=new Date() var hours=Digital.getHours() var minutes=Digital.getMinutes() var seconds=Digital.getSeconds() var dn="PM" if (hours<12) dn="AM" if (hours>12) hours=hours-12 if (hours==0) hours=12 if (minutes<=9) minutes="0"+minutes if (seconds<=9) seconds="0"+seconds var ctime=hours+":"+minutes+":"+seconds+" "+dn thelement.innerHTML="<b style='font-size:14;color:blue;'>"+ctime+"</b>" setTimeout("showtime()",1000) } window.onload=showtime </script> |
2. Insert this into the :
| <span id=tick2></span> |
3. To change the clock color look at
| thelement.innerHTML="<b style='font-size:14;color:blue;'>"+ctime+"</b>" |
You can change "color:blue;" to something like "color:red;" or "color:black;" etc..
Enjoy!
Related Articles
- 12/24 Hour ClockA standard java script clock that has the added functionality of letting the user decide whether the time is displayed in 12 for 24 hour format. A nice bit of code that has not tried to be overly complex in displaying the time.
- Binary ClockHours, minutes and seconds java script clock, with the twist that the time is displayed in binary! An unusual script, that gives a nice twist to the standard java script clock. The only down side is that you need to understand binary to read the time.
- The Basics- JavaScript TutorialTo get started with JavaScript, you will want to be able to see the tag that will set a script apart from the HTML. The tags used to begin and end a script are the tags. The opening tag should appear like this
- 4 Powerful Features of Javascript Programming LanguageIn the community of web developers and surfers, Javascript is highly popular as client side scripting language for web browsers. Lets take a look at some of the features of this language.
- JavaScript PromptsWell, lets say you wanted to get somebodys name before they saw the page, and then write their name on your page right before their very eyes... Well, you can do this using a javascript prompt. Heres the command:
- Introduction to Javascript for NewbiesJavascript is a client-side programming language whose processing engine is embedded in web browsers like Internet Explorer, Netscape, Firefox, etc. This enables the processing engine to read and interpret web pages that contain the javascript code when browsing
- Form ValidationLearn the different ways of validating your form with Javascript.
- Statusbar MessageThis is a quick, and quite simple tutorial. Now its not html, it uses Javascript. What it does is lets you customize what it says in the status bar usually at the bottom left of your browser. Right now in your browser it should say Infinite Designs.org ..... Heres how to make it do that...
- Stop Right Mouse ClicksStop people from getting at your source by right clicking on your web page. Sounds good, but doesnt protect you totally, you can never fully protect your work, but it will make it harder.
- Changing the Background ColourYet another snippet of JavaScript code, folks. This time well be using JavaScript to change a background color with a MouseOver and a mouse click.
