jQuery | javascript | CSS

31.jQuery - Text ( 03..Attributes - 05.Text )

Godffs 2009. 11. 10. 10:45
반응형

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]



반응형