달력

02

« 2012/02 »

  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  •  
  •  
  •  
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>
        &lt;div class="demo-container"&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class="demo-box"&gt;Demonstration Box&lt;/div&gt; <= 결과값<br>
        &lt;/div&gt;<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>
        &lt;div class="demo-container"&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class="demo-box"&gt;Demonstration Box&lt;/div&gt; <= 이 부분 교체<br>
        &lt;/div&gt;<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
Posted by -세티-