Nội dung chính Show
Định nghĩa và sử dụng
Cấu trúc.prepend(nội dung)nội dung) $('div').prepend('<p>nội dung thêm vào</p>'); $('div').prepend($('h3')); .prepend(nội dung)Ví dụ thêm<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('div').prepend('<p>nội dung thêm vào</p>');
});
</script>
</head>
<body>
<div>Thành phần div</div>
<div>Thành phần div</div>
</body>
</html> .prepend(): Chèn nội dung vào trong thành phần ở vị trí đầu tiên.Html viết:prepend thì thành phần div được chèn thêm thành phần nội dung thêm vào Hiển thị trình duyệt:
Ví dụ thêmVí dụ thêm<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('div').prepend($('h3'));
});
</script>
</head>
<body>
<div>
<p>thành phần p</p>
<h3>thành phần h3</h3>
</div>
</body>
</html> .prepend(): Chèn nội dung vào trong thành phần ở vị trí đầu tiên.Html viết: Hiển thị trình duyệt:
.prepend(function(index){...})Ví dụ thêm<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('div').prepend(function() {
return '<p>' + this.className + '</p>';
});
});
</script>
</head>
<body>
<div class="test01">thành phần div 01</div>
<div class="test02">thành phần div 02</div>
</body>
</html> .prepend(): Chèn nội dung vào trong thành phần ở vị trí đầu tiên.Html viết: Hiển thị trình duyệt:
Định nghĩa và sử dụng
Cấu trúc
.prepend(nội dung)nội dung) $('div').prepend('<p>nội dung thêm vào</p>'); $('div').prepend($('h3'));
.prepend(nội dung)Ví dụ thêm<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('div').prepend('<p>nội dung thêm vào</p>');
});
</script>
</head>
<body>
<div>Thành phần div</div>
<div>Thành phần div</div>
</body>
</html> .prepend(): Chèn nội dung vào trong thành phần ở vị trí đầu tiên.Html viết:prepend thì thành phần div được chèn thêm thành phần nội dung thêm vào Hiển thị trình duyệt:
Ví dụ thêmVí dụ thêm<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('div').prepend($('h3'));
});
</script>
</head>
<body>
<div>
<p>thành phần p</p>
<h3>thành phần h3</h3>
</div>
</body>
</html> .prepend(): Chèn nội dung vào trong thành phần ở vị trí đầu tiên.Html viết: Hiển thị trình duyệt:
.prepend(function(index){...})Ví dụ thêm<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$('div').prepend(function() {
return '<p>' + this.className + '</p>';
});
});
</script>
</head>
<body>
<div class="test01">thành phần div 01</div>
<div class="test02">thành phần div 02</div>
</body>
</html> .prepend(): Chèn nội dung vào trong thành phần ở vị trí đầu tiên.Html viết: Hiển thị trình duyệt:
|