본문 바로가기
HTML

38일차//JQuery// button클릭시(태그 추가) 🧨text 추가방법 3가지(스크립트, 제이쿼리)

by aesup 2021. 3. 8.
728x90
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src = "https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>

<button type="button">tag append</button>

<script type="text/javascript">
$(function () {
	$("button").click(function () {
		//방법 3가지
		
		//html (text)추가
		let txt = "<p>html p tag append</p>";
		$("body").append(txt);
		
		//java스크립트 추가
		let js = document.createElement("h3");
		js.innerHTML = "js h3 tag append";
		$("body").append(js);
		
		//jQuery추가
		let jq = $("<p></p>").text("jQuery p tag append");
		$("body").append(jq);
	});
});


</script>

</body>
</html>

728x90