31.jQuery - Text ( 03..Attributes - 05.Text )
05.Text.htm |
<html xmlns="http://www.w3.org/1999/xhtml"> <head>
<title>텍스트 값 가져오기 및 설정</title>
<script src="../jQuery/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
{ //get var
text = $('b').text(); alert(text); //set $('p:first').text("<b>낼</b> 봐요"); //first붙이지 않으면 인코딩하여 문자열로 출력 $('p:last').html("<b>낼</b>봐요."); //html은 자체에서 인코딩 //[!] 15줄을 alert로 출력해서 다른 결과값을 확인해보자 //get html값 가져와서 창으로 띄우기 alert($('p:last').html); //alert창은 text로만 띄운다.
});
</script>
</head> <body>
<div>
안녕하세요. <b>jQuery</b><hr />
반가워요. <b>jQuery</b><hr />
<p>또 만나요</p>
<p>언제요?</p>
</div>
</body> </html> |
결과확인 |
[그림31-1] |