jQuery - html(), text()
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
// html() - 자바스크립트의 innerHTML과 기능이 동일
// text()
var h = $('h1').html();
//alert(h);
var t = $('h1').text();
//alert(t);
//$('div').text('<h1>text Method</h1>');
//$('div').html('<h1>html Method</h1>');
// 배열형태로 하나씩 접근
// $('div').html(function (index) {
// return '<h1>html Method - ' + index + '</h1>';
// });
$('h1').html(function (index, oldHtml) {
return '★' + oldHtml + '★';
});
});
</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
<h1>head-0</h1>
<h1>head-1</h1>
<h1>head-2</h1>
</body>
</html>