BobbyFrankyJim Posted August 9, 2010 Share Posted August 9, 2010 Hello everyone I just started learning HTML, CSS and Javascript and I was wondering if it is possible to format javascript results. I have made a clock on my website but I want it to be in the center not to the left, how do I change that? Link to comment Share on other sites More sharing options...
Ingolme Posted August 9, 2010 Share Posted August 9, 2010 You can put the result within an element that's styled with CSS, or you can style the containing element with the .style property. Link to comment Share on other sites More sharing options...
BobbyFrankyJim Posted August 9, 2010 Author Share Posted August 9, 2010 I tried but I do not exactly know how to do it which section is formatted? Link to comment Share on other sites More sharing options...
Ingolme Posted August 9, 2010 Share Posted August 9, 2010 Hmm, you might need to post an example of your code and what you're trying to achieve, exactly.Depending on how you're putting the results in the elements, styling them may require different techniques. Link to comment Share on other sites More sharing options...
BobbyFrankyJim Posted August 9, 2010 Author Share Posted August 9, 2010 Here is the code: <script type="text/javascript">function startTime(){var today=new Date();var h=today.getHours();var m=today.getMinutes();var s=today.getSeconds();// add a zero in front of numbers<10m=checkTime(m);s=checkTime(s);document.getElementById('txt').innerHTML=h+":"+m+":"+s;t=setTimeout('startTime()',500);}function checkTime(i){if (i<10) { i="0" + i; }return i;}</script></head><body onload="startTime()"><div id="txt"></div> Link to comment Share on other sites More sharing options...
Ingolme Posted August 9, 2010 Share Posted August 9, 2010 You just need to put CSS on the div: #txt { text-align: center; } Link to comment Share on other sites More sharing options...
BobbyFrankyJim Posted August 9, 2010 Author Share Posted August 9, 2010 Thanks Link to comment Share on other sites More sharing options...
BobbyFrankyJim Posted August 9, 2010 Author Share Posted August 9, 2010 I have tried to put it in, but I think I am putting it in the wrong spot should it be <div id="txt">{ text-align: center; }</div>? Link to comment Share on other sites More sharing options...
dsonesuk Posted August 9, 2010 Share Posted August 9, 2010 he means place in where your javascript code is placed between head tags<script type="text/javascript">function startTime(){var today=new Date();var h=today.getHours();var m=today.getMinutes();var s=today.getSeconds();// add a zero in front of numbers<10m=checkTime(m);s=checkTime(s);document.getElementById('txt').innerHTML=h+":"+m+":"+s;t=setTimeout('startTime()',500);}function checkTime(i){if (i<10) { i="0" + i; }return i;}</script><style type="text/css">#txt { text-align: center; }</style></head><body onload="startTime()"><div id="txt"></div> Link to comment Share on other sites More sharing options...
Ingolme Posted August 9, 2010 Share Posted August 9, 2010 You should look at the W3Schools CSS tutorialIf you're already into Javascript you really should know CSS by now. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.