본문 바로가기

jQuery

[jQuery] text 메소드와 html 메소드

반응형

[jQuery] text 메소드와 html 메소드



 text.html

<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>text 메소드</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function() {

        // jQuery("선택자").text() => 태그값을 반환 받는 메소드(HTML 태그가 미포함)
        alert(jQuery("h2").text());

        // jQuery("선택자").text("변경값") => 태그값을 변경 하는 메소드(HTML 태그가 미인식)
        jQuery("h3").text("<font color='blue'>jQuery 연습</font>");
    });
</script>
</head>
<body>
    <h1>text 메소드</h1>
    <hr/>
    <h2><font color="red">jQuery 연습</font></h2>
    <h3>jQuery 연습</h3>
</body>
</html>

 출력결과 

 출력결과



 html.html

<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>html 메소드</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function() {

        // jQuery("선택자").html() => 태그값을 반환 받는 메소드(HTML 태그가 포함)
        alert(jQuery("h2").html());

        // jQuery("선택자").html("변경값") => 태그값을 변경 하는 메소드(HTML 태그가 인식)
        jQuery("h3").html("<font color='blue'>jQuery 연습</font>");
    });
</script>
</head>
<body>
    <h1>html 메소드</h1>
    <hr/>
    <h2><font color="red">jQuery 연습</font></h2>
    <h3>jQuery 연습</h3>
</body>
</html>

 출력결과

 출력결과


반응형

'jQuery' 카테고리의 다른 글

[jQuery] jQuery 엘리먼트  (0) 2015.12.28
[jQuery] jQuesy 이벤트  (0) 2015.12.20
[jQuery] attr 메소드  (0) 2015.12.20
[jQuery] css 메소드  (0) 2015.12.20
[jQuery] each 메소드  (0) 2015.12.20