+ 3

Can someone help me style this javascript code

So I want to make time more bold <stromg> and the font size bigger with css where put .css after the js or any other way to make it more noticable. Here is the Code: <script type="text/javascript"> function clockTick () { currentTime = new Date (); month = currentTime.getMonth ()+1; day = currentTime.getDate (); year = currentTime.getFullYear (); setInterval (clockTick, 1000); return (year+ "/" +month+"/"+day); } document.write (clockTick ()); </script>

11th Jun 2017, 3:20 PM
SauceCode
SauceCode - avatar
2 ответов
+ 6
document.write('<strong style="font-size:1.5em;">'+clockTick()+'</strong>'); But your code will not work as you probably expect: The setInterval() call will regurlarly recall the clockTick() function, but each execution will not update any display content (the function only return the date string formatted, wich you only document.write() on first call ^^ Anyway, document.write is not the good solution for update content, as when it occurs after page loaded, it will implicitly close the actual document and open a new empty one... To display regurlarly date/time update, rather use 'innerHTML' property of an html element... As you seem not master in html/css, use the <body> (always present, even if implicitly created by browsers), just be sure to access it after it's already parsed. To be safe, change your code to: Can someone help me style this javascript code So I want to make time more bold <stromg> and the font size bigger with css where put .css after the js or any other way to make it more noticable. Here is the Code: <script type="text/javascript"> function clockTick() { currentTime = new Date (); month = currentTime.getMonth ()+1; day = currentTime.getDate (); year = currentTime.getFullYear (); document.body.innerHTML='<strong style="font-size:1.5em;">'+year+'/' +month+'/'+day+'/strong>'; setInterval (clockTick, 1000); } window.onload = clockTick; </script> However, displaying the date (not the hours/minutes) doesn't require a 1000ms second refresh ;)
11th Jun 2017, 7:33 PM
visph
visph - avatar
+ 1
Thanks
12th Jun 2017, 6:40 AM
SauceCode
SauceCode - avatar