2013-04-26 2 views
0

이것은 너무 오랫동안 코드를 쳐다보고 중요한 것을 놓친 또 다른 인스턴스입니다. 기본적으로 WebKit에서 .click (jQuery) 이벤트가 발생하면 클릭 된 항목의 내용으로 다른 스크립트를 채 웁니다. 그러나 어떤 이유로 항목을 여러 번 클릭하면 DOM 요소가 삭제됩니다. 어떤 아이디어? 아래에 링크 된 코드 샘플을 가진 JSFiddle.:Javascript가 DOM 요소를 삭제합니다.

$(".vote-divs .vote-div").click(function() { 
     $(".vote-none").hide() 
     $(".step-2-column-left .vote-div").each(function() { 
      $(this).hide(); 
     }); 
     $("#" + $(this).attr("id") + "-s").show(); 

     $(".confirm-s").each(function() { 
      $(this).hide(); 
     }); 

     if ($(this).attr("id") == "vote-grow") { 
      $("#donation-vote-for").val("Grow"); 
      $("#confirm-grow-s").show(); 
     } else if ($(this).attr("id") == "vote-stache") { 
      $("#donation-vote-for").val("Stache"); 
      $("#confirm-stache-s").show(); 
     } else if ($(this).attr("id") == "vote-shave") { 
      $("#donation-vote-for").val("Shave"); 
      $("#confirm-shave-s").show(); 
     } else if ($(this).attr("id") == "vote-mutton") { 
      $("#donation-vote-for").val("Mutton"); 
      $("#confirm-mutton-s").show(); 
     } else if ($(this).attr("id") == "vote-manchu") { 
      $("#donation-vote-for").val("Manchu"); 
      $("#confirm-manchu-s").show(); 
     } 


     console.log(event.target); 
     $(".vote-none").html(event.target); 

     goTo("3"); 
    }); 

JSFiddle

+0

삭제되거나 숨겨져 있습니다 ... ?? –

답변

0

$(".vote-none").html($(event.target).clone()); 

대신

$(".vote-none").html(event.target); 

데모 시도 : 여기

내가 범인이라고 생각하는 기능입니다3210

+0

그게 고쳐 줘서 고마워! –

0

.html()은 문자열을 필요로합니다. 노드를 제공합니다. 그렇게하면 jQuery가이 노드를 가져와 다른 요소에 추가합니다. 당신이 정말로 다른 하나의 내용와 요소를 채우려는 경우, 해결 방법은 경우에 thisevent.target에 해당된다는

$(".vote-none").html(event.target.innerHTML); 

또는

$(".vote-none").html($(this).html()); 

주입니다.

관련 문제