본문 바로가기

[ programing ]/JavaScript + JQuery

html콘텐츠를 읽어 다른엘리먼트의 html콘텐츠로 설정



<script>

$(document).ready(function(){

$('#wrapper').html($('#hidden').html()); // waapper의 내용을 hidden의 내용으로 교체


});

</script>






<div id="wrapper">

<span id = "test">이곳의 내용을 바꿔 주세요.</span>

</div>

<div id="hidden">

<ul>

<li>1</li>

<li>2</li>

<li>3</li>

<li>4</li>

</ul>

</div>




// 기존 html 콘텐츠를 삭제하고 wrapper의 엘리먼트가  추가됨...











<script>

$(document).ready(function(){

 $('#wrapper').html('<ul><li>1</li><li>2</li></ul>');


});

</script>