본문 바로가기

컴퓨터 프로그래밍/JQuery

append(), after(), prepend(), before()

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>태그에 내용이 붙는 것::append(), after()||prepend(), before()</title>
<style type="text/css">
	body{
	padding: 50px;
	}
	div{
	border: 2px solid #bbb;
	padding: 10px;
	margin: 10px auto;
	background-color:#eee;}
	span{
	display:block;
	width: 65px;
	pont: bold 12px Arial, sans-serif;
	color: white;
	padding: 5px 10px;
	background-color: black;}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	$('div')
	.append('<span>1.Append</span>')
	.after('<span>2.After</span>')
	.prepend('<span>3.Prepend</span>')
	.before('<span>4.Before</span>')
});
</script>
</head>
<body>
<div>jQuery is a fast, small, and feature-rich JavaScript library. 
     It makes things like HTML document traversal and manipulation, event handling, animation,
     and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. 
     With a combination of versatility and extensibility, 
     jQuery has changed the way that millions of people write JavaScript. </div>
</body>
</html>