※ set적용- text(), html() -1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
// text => js contentText메소드와 동일한 효과
$("#test1").text("Hello world!");
});
$("#btn2").click(function(){
// html => js의 innerHTML메소드와 동일한 효과
$("#test2").html("<b>Hello world!</b>");
});
$("#btn3").click(function(){
// val => js의 value메소드와 동일한 효과
$("#test3").val("Dolly Duck");
});
});
</script>
</head>
<body>
<p id="test1">This is a paragraph.</p>
<p id="test2">This is another paragraph.</p>
<p>Input field: <input type="text" id="test3" value="Mickey Mouse"></p>
<button id="btn1">Set Text</button>
<button id="btn2">Set HTML</button>
<button id="btn3">Set Value</button>
</body>
</html>
※ 실행화면 -1
※ set적용- text(), html() -2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("#test1").text(function (i, origText){
return "Old text: " + origText + "New text : Hello world!(index: " + i +")";
});
});
$("#btn2").click(function(){
$("#test2").html(function(i, origText){
return "Old html: " + origText + "New html: Hello <b>world!</b> (index: " + i + ")";
});
});
});
</script>
</head>
<body>
<p id="test1">This is a <b>bold</b> paragraph.</p>
<p id="test2">This is another <b>bold</b> paragraph.</p>
<button id="btn1">Show Old/New Text</button>
<button id="btn2">Show Old/New HTML</button>
</body>
</html>
※ 실행화면 -2
'jQuery 수업' 카테고리의 다른 글
jQuery-14(add적용 - append()) (0) | 2020.02.19 |
---|---|
jQuery-13(set적용-attr()) (0) | 2020.02.19 |
jQuery-11(get적용- text(), html()) (0) | 2020.02.19 |
jQuery-10(css- color 적용) (0) | 2020.02.19 |
jQuery-9(animate()- slideDown()) (0) | 2020.02.19 |