1 Replies - 393 Views - Last Post: 25 July 2014 - 11:33 AM

#1 mored  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 31-August 12

need button to clear time

Posted 25 July 2014 - 11:20 AM

<!doctype html>



<html lang="en">



<head>
	
<meta charset="utf-8">
		
<title>Javascript Testbed</title>
		
		
<script type="text/javascript"> 
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh)
}

function display_ct() 

{
var strcount
var x = new Date()
document.getElementById('ct').innerHTML = x;
tt=display_c();
}
		
</script>		
		
		
    </head>
	
	
	
	
    <body onload=display_ct();>
	
	
	
        <h1>
            Javascript will find out the date and the browser.
        </h1>
		
		
    
	<script type="text/javascript">
	
            var currentTime = new Date();
            var hours = currentTime.getHours();
            var minutes = currentTime.getMinutes();
			var seconds = currentTime.getSeconds();
            var suffix = "AM";

            if (seconds < 10)
                seconds = "0" + seconds;
			
			
			if (minutes < 10)
                minutes = "0" + minutes;

            if (hours >= 12) {
                suffix = "PM";
                hours = hours - 12;
            }
            if (hours == 0) {
                hours = 12;
            }

            document.write("<b><div id='d1'>" + hours + ":" + 
                minutes + ":" + seconds + " " + suffix + "</div></b>");
				
				
				
				
				
function hideElement(id_attribute_value) {
			  if (document.getElementById &&
				  document.getElementById(id_attribute_value) &&
				  document.getElementById(id_attribute_value).style
			  ) {
				   document.getElementById(id_attribute_value).style.visibility = "hidden";
			  };
			}        


    </script>
	
	
	
	
	
	
	
	<button type="button" onclick="hideElement('d1');">hide div</button>
	
		
		

	
	</body>
	
	
	
	
	
</html>



I need to clear the time when hide button is clicked; any suggestions?

Is This A Good Question/Topic? 0
  • +

Replies To: need button to clear time

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,383
  • Joined: 15-January 14

Re: need button to clear time

Posted 25 July 2014 - 11:33 AM

Clicking the button will hide the div, isn't that what you're trying to do? If you want to clear the content from that div then get a reference to it with getElementById and set the innerHTML property to an empty string.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1