<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" language="javascript" src="jquery-1.4.2.js"></script>
<style type="text/css"> p { margin:8px; font-size:20px; color:blue; cursor:pointer; } b { text-decoration: underline; } button { cursor: pointer; } </style>
</head>
<body>
<h4>.html(): 이것은 xml 문서에서는 이용할 수 없다. 매치된 엘리먼트 집합의 첫번째 엘리먼트가 포함하는 html을 반환</h4>
$('div.demo-container').html();<br>
<div class="demo-container"><br>
<div class="demo-box">Demonstration Box</div> <= 결과값<br>
</div><br><br>
<p><b>Click</b> to change the <span id="tag">html</span></p>
<p> to a <span id="text">text</span> node.</p>
<p> This <button name="nada">button</button> does nothing.</p>
<script> $("p").click( function() { var htmlStr = $(this).html(); $(this).text(htmlStr); }); </script>
<h4>.html( htmlString ): 매치된 엘리먼트가 포함하는 HTML을 문자열로 설정한다.</h4>
$('div.demo-container').html();<br>
<div class="demo-container"><br>
<div class="demo-box">Demonstration Box</div> <= 이 부분 교체<br>
</div><br><br>
<div class="demo-container">
<div class="demo-box">Demonstration Box</div>
</div>
<script> $('div').html('<p>All new content. <em>You bet!</em></p>'); </script>
<h4>jQuery 1.4에서는 함수를 이용하여 값 바인딩이 가능</h4>
<div class="demo-container1">
<div class="demo-box">Demonstration Box</div>
</div>
<script> $('div.demo-container1').html( function() { var emph = '<em>' + $('p').length + ' paragraphs!</em>'; return '<p>All new content for ' + emph + '</p>'; }); </script>
<h4>각각의 div에 약간의 html을 추가</h4>
<div></div>
<div></div>
<div></div>
<script> $("div").html("<b>Wow!</b> Such excitement..."); $("div b").append(document.createTextNode("!!!")).css("color", "red"); </script>
</body>
</html>