[ReplaceWith.htm]


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title>검색된 요소를 변경하기</title>

    <style type="text/css">

        button { display:block; margin:3px; color:red; width:200px; }

        div { color:red; border:2px solid blue; width:200px;

                margin:3px; text-align:center; }

    </style>

    <script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function () {

            // 모든 버튼 요소 클릭시

            $("button").click(function() {

                // 나자신(버튼) <div> 태그로 변경하자.

                $(this).replaceWith("<div>" + $(this).text() + "</div>");

            });

        });

    </script>

</head>

<body>

    <button>First</button>

    <button>Second</button>

    <button>Third</button>

</body>

</html>

 



-------------------------------------------------------------------------------------

 


[실행결과]

--> 첫 화면.
 





--> 첫 번째 버튼을 클릭하면 아래그림과 같이 해당 버튼이 "<div> 태그"로 변경된다.




--> 두 번째 버튼을 클릭하였을 때의 화면.(해당버튼이 "<div> 태그"로 변경되었다.)


 

 

 

Posted by holland14
: