스크립트 이벤트 순서가 자식노드에서부터 상위 부모노드로 올라가면서 연속적으로 실행되는 것을 말한다.


<html>
<head>
	<style type="text/css">
		.parent {width:300px; height:300px; background-color:red;}
		.child {width:150px; height:150px; background-color:yellow;}
	</style>
	<script type="text/javascript">
	function parent(){
		alert("parent clicked");
	}
	
	function child(){
		alert("child clicked");
	}	
	</script>
</head>
<body>
	<div onclick="parent();" class="parent">
		<div onclick="child();" class="child"></div>
	</div>
</body>
</html>




위 코드를 실행하면 나오게 되는 화면이다.

부모 <div>와 자식 <div>가 겹쳐지는 부분인 노란색 영역을 클릭하게 되면 "child clicked" 얼럿이 뜨고 나서 "parent clicked" 얼럿이 뜨게 된다.


이것을 막기 위해선 event 속성의 cancleBubble값을 true로 설정하여야 한다.


	function child(){
		alert("child clicked");
		event.cancelBubble = true;
	}


또는 jQuery를 통해서 다음과 같이 처리할 수도 있다.


	jQuery(".child").click(function(e){
		e.stopPropagation();
	});



Posted by SungHoon, Park
,