본문 바로가기

개발/JavaScript

[JavaScript] innerHTML, document.write(), alert(), console.log() 사용법

innerHTML, document.write(), alert(), console.log() 사용법



innerHTML

innerHTML 을 사용하면 HTML 문서안에는 태그의 내용을 가져오거나 변경할수있다.
document.getElementId() 또는 document.getElementName() 과 같이 Element 객체에 불러와 사용한다.


js

html
	
	

hi


위와 코드에서는 

sample.innerHTML 은 태그안의 내용을 가져오는것이며
sample.innerHTML = "bye" 는 태그안의 내용을 bye 로 변경할수있다.


document.write()

document.write()는 문서안의 텍스트 또는 연산된 숫자를 넣을수있다.




window.alert()

window.alert() 는 메세지박스를 띄어 사용자에게 메세지를 전달할때 사용한다.

js

html
	
	

hi


console.log()

console.log는 말그대로 콘솔에 로그를 남길때 사용하는데,
콘솔은 개발자모드(F12) 에서 확인할수있다.
주로 디버깅용도로 사용한다.

js

html
	
	
	
	


위의 소스코드를 실행해보면 아래와같이 로그를 확인할수 있다.