커피와 개발자

[jQuery] append() 한 내용에 대한 click() 접근이 안되는 경우 본문

웹개발/제이쿼리(jQuery)

[jQuery] append() 한 내용에 대한 click() 접근이 안되는 경우

광박이 2011. 4. 14. 12:29
728x90
Html += '<li><a style="cursor:hand">링크</a></li>'; 
$('#divID').append(Html);

위와 같이 html 생성 후 append() 시킨 후에 append() 한 DOM에 대하여
$('#divID').click(function() {
// 실행
});

click() 액션을 통해 접근을 할 경우
크롬, 파폭에서는 정상 동작 하지만 IE 에서는 정상적으로 동작을 하지 않는 경우
 
$('#divID').live('click',(function() {
//실행
}));

와 같은 형식으로 수정
live() 처리를 하면 새로운 callback 처리가 가능

you could use one of jQuery's fancy plugins like liveQuery which monitors the DOM for changes and then re-assigns the event's function when you add something. Although, be careful because liveQuery doesn't really monitor the DOM; it just extends jQuery's 'append','prepend','html',etc. methods and re-assigns when something is added, so if you add something to the DOM using another library or native JavaScript methods then liveQuery will not work.
728x90
Comments