2010-04-21 7 views
0

이것은 간단한 대답 일지 모르지만 dom 작성 요소 (즉, document.createElement(...))를 jQuery Selector에 추가하려고합니다.jQuery DOM 요소 추가

jQuery를은 HTML을 추가하기위한 기능의 큰 구색을 가지고

  • .html 중에서 (htmlString)
  • 으로 .Append (htmlString)
  • .prepend (htmlString)

하지만 난 돔을 추가하는 것입니다 OBJECT

var myFancyDiv = document.createElement("div"); 
myFancyDiv.setAttribute("id", "FancyDiv"); 

// This is the theoretical function im looking for. 
$("#SomeOtherDiv").htmlDom(myFancyDiv); 

답변

3

이 시도 :

$("#SomeOtherDiv").append($(myFancyDiv)); 

$ (...)에서 DOM 요소를 포장

, 나는 당신이 jQuery를 요소 컬렉션을 JQuery와 DOM 조작 기능의 그것을 추가 할 수 있습니다 기대.

+2

당신 돈 jQuery로 DOM 객체를 추가해야한다. '$ ("# SomeOtherDiv")를 할 수 있습니다. append (myFancyDiv)' – Anurag

1

이렇게해야합니다!

$("#SomeOtherDiv").append('<div id="FancyDiv"></div>')); 
1

당신은 완전히이 간단한 뭔가 jQuery를 절단하여 일을 간단하고 빠르게 만들 수에서 작동합니다 :

document.getElementById("SomeOtherDiv").appendChild(fancyDiv);