2 + 3 - 1 :
이러한 계산식이 있을 경우 2, +, 3, -, 1(토큰)으로 나누어 parse tree를 만든다.
<html> <body> <p> Hello </p> <div> <img src="example.png"/></div> </body> </html>
브라우저는 html(마크업)을 엘리먼트(요소)들 즉 html, body, paragraph, div 로 나누어 트리형 식으로 만들어 브라우저가 처리를 한다. 이 트리를 DOM Tree라고 한다
CSS :
p, div { margin-top:3px; } .error { color:red; }
예시
<html> <body> <script src="http://www.naver.com"></script> <script>alert(1)</script> <p>Hello</P> </body> </html>
브라우저가 HTML 파일을 읽을 때(파싱 할 때) script 태그를 만난 순간 서버에 그 파일을 요청하고 먼저 실행할 js가 가 있으면 실행한다. 또한 문제는 예시와 같이 alert(1) 가 사용자가 확인 버튼을 누를 때까지 p 태그는 출력 되지 않는다 그래서 보통 script는 body 태그의 끝 한 라인 전후에 위치한다.
<html> <body> <p>Hello</p> <script src="http://www.naver.com"></script> <script>alert(1)</script> </body> </html>
Main flow가 핵심이며 위의 내용들을 참고하시면 좋을듯 합니다.