2012-11-10 4 views
-1

jquery에 대한 지식이 없습니다. 아래 코드가하는 일을 어떤 몸으로 안내 할 수 있습니까? 나는 그것을 봤지만 어떤 결과도 찾지 못했습니다. div 안에 div 콘텐츠를 추가하고 싶습니다. 클래스는 'p-notification'입니다. 이 작업을 수행하는 방법?DIV 요소 만들기 및 HTML 내용 추가

this.notification = $('<div/>', { 
      'class': 'p-notification' 
}); 
this.content = $('<div/>', { 
     'class': $elem.attr("hasFooter") === "true" ? 'p-content with-p-footer' : 'well', 
     'style': $elem.attr("paddless") === "true" ? 'padding:0;' : '',  
     'text': 'Loading' 
}); 
+0

JQuery의 사람들은 웹 사이트를 가지고 있습니다. – GolezTrol

+0

[jquery documentation for DOM Insertion] (http://api.jquery.com/category/manipulation/dom-insertion-inside/)을 확인하는 것이 좋습니다. –

+0

안녕하세요 Ranjan이 귀하의 문제이거나 다른 것입니다. 너의 질문은 downvoted 참조하십시오. – Jai

답변

1

다음 부분은 추가 또는 클래스 p-notification 함께 새롭게 작성된 div 요소로 범위에 notification 속성을 설정

this.notification = $('<div/>', { 
      'class': 'p-notification' 
}); 

다음 부분에서 추가하거나하는 범위에 content 속성을 설정 새로 만들어진 div 요소이며 미리 설정된 속성이 여러 개 있습니다. class, styletext :

this.content = $('<div/>', { 
     'class': $elem.attr("hasFooter") === "true" ? 'p-content with-p-footer' : 'well', 
     'style': $elem.attr("paddless") === "true" ? 'padding:0;' : '',  
     'text': 'Loading' 
}); 

요소를 만들었지 만 문서에 요소를 삽입하지 않았으므로 DOM에 아무런 영향을 미치지 않습니다. 당신은 콘텐츠를 추가하려면이 같이 할 수

$('#somediv').append(this.content);//adds the div that was created to an element with id somediv 
1

: 당신은 jQuery를에 의해 제공 several methods 중 하나, 예를 들어 append를 사용하여 삽입 할 수 있습니다

$('.p-notification').append('<div>Hey</div>'); 

또는이 콘텐츠 교체 :

$('.p-notification').html('<div>Hey</div>');