2013-02-10 1 views
0

나는 다음과 같은 HTML 내용이 : 나는 위의 HTML 내용에서 단지 strongp 요소를 복제 할 필요가jquery를 사용하여 html 콘텐츠를 복제하는 방법은 무엇입니까?

<div data-test='sectionA'> 
    <input type="text" /> 
    <strong>sfdsfds</strong> 
    <p>dffdfdsf</p> 
</div> 

합니다.

우선이 부분을 확인해야합니다 : 여기 내 시도 내가 jQuery를 사용하고 있지 않다

if($("div").data("test") == "sectionA") 
{ 
    $(this).children().not("input").each(function() 
    { 
      alert($(this).html().clone()); 
      /* firefox says clone is not a function 
       and I'm not getting <strong>dfadfa</strong> 
       or the <p>sfdasdfsd</p> clone copy */ 

     }); 
} 
+0

,하지만 나는'.html 중에서는()'문자열을 반환 생각합니다. 또한 문자열이 아닌 HTML 요소 만 복제 할 수 있습니다. 그것을 제거해보십시오 – Oriol

+0

'html' 함수는 노드/객체가 아닌 문자열을 반환하므로 복제 할 것이 없습니다. –

+0

복제본 사본이 주석의 일부 여야합니다. –

답변

1
var $div = $("div[data-test=sectionA]"); 
var $strong = $('strong', $div).clone(); 
var $p = $('p', $div).clone(); 
관련 문제