2010/07/27 09:15
jQuery-.html() General Web2010/07/27 09:15
<!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>
<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>
'General Web' 카테고리의 다른 글
| jQuery - .hasClass() (0) | 2010/07/28 |
|---|---|
| jQuery-.html() (0) | 2010/07/27 |
| jQuery - .attr() (0) | 2010/07/27 |
| jQuery - 엘리먼트에 클래스 추가/삭제 하기. (0) | 2010/07/26 |
| ASP + AJAX(JSON) (0) | 2010/06/18 |
| Javascript를 이용한 개발에서의 MVC 패턴 (2) | 2009/02/11 |
