개발/Javascript

[Javascript] innerText, innerHtml

suniverse 2023. 1. 14. 21:45

<script type="text/javascript">
	function innText(){
		let now = new Date();
		document.getElementById("currentTimeText").innerText = "<h3>" + now + "</h3>";
	}
	function innHtml(){
		let now = new Date();
		document.getElementById("currentTimeHtml").innerHTML = "<h3>" + now + "</h3>";
// 		alert(document.getElementById("currentTimeHtml"));		
		
	}
</script>
</head>
<body>
	<h1>test31.html</h1>
	<button onclick="innText()">innerText로 표시하기</button>
	<button onclick="innHtml()">innerHtml로 표시하기</button>
	<hr>
	<h1>현재 시각 Text</h1>
	<div id="currentTimeText"></div>
	<hr>
	<h1>현재 시각 Html</h1>
	<div id="currentTimeHtml"></div>
</body>

💻