#new-post
내용이 있는 클래스 속성을 추가하고 싶습니다.<script type="text/template" id="template"></script>
아래는 '템플릿'의 내용을 찾을 수 있지만 클래스 속성을 추가 할 수없는 코드입니다.
$('#template').contents().find('#new-post').addClass('hello');
HTML
<script type="text/template" id="template">
<div id="new-post">
</div>
</script>
스크립트 요소는 CDATA를 포함하며 하위 요소를 가질 수 없습니다 <
(태그가 인 경우를 제외하고 그 안에 "태그의 시작"을 의미하지 않음 </script>
).
템플릿 콘텐츠의 DOM 조작을 수행하려면 먼저 템플릿을 DOM으로 구문 분석해야합니다.
var template = $('#template').text();
var $template = $(template);
$template.addClass('hello');
alert($template.wrap('<div></div>').parent().html());
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다