replaceAll(selector) trong jQuery
Miêu tả
Phương thức replaceAll(selector) trong jQuery thay thế các phần tử đã so khớp bởi Selector đã cho với các phần tử được so khớp.
Cú pháp
Sau đây là cú pháp cho replaceAll(selector) trong jQuery:
selector.replaceAll( selector )
Tham số
Dưới đây miêu tả chi tiết về các tham số được sử dụng trong phương thức replaceAll(selector) trong jQuery:
selector − Các phần tử để tìm và thay thế cho các phần tử đã so khớp.
Ví dụ
Sau đây là ví dụ đơn giản minh họa cách sử dụng của phương thức replaceAll(selector) trong jQuery. Nó thay thế hình vuông được click bởi một khối mới.
<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("div").click(function () {
$('<div class="div"></div>').replaceAll( this );
});
});
</script>
<style>
.div{ margin:10px;padding:12px; border:2px solid #666; width:60px;}
</style>
</head>
<body>
<p>Click on any square below to see the result:</p>
<div class="div" style="background-color:blue;">ONE</div>
<div class="div" style="background-color:green;">TWO</div>
<div class="div" style="background-color:red;">THREE</div>
</body>
</html>
Nó sẽ cho kết quả:
Công cụ giáo viên (2048.VN)
Tạo- trộn đề thi miễn phí từ file PDF, Word, Giao bài nhanh chóng, Hoàn toàn Free
Các bài học jQuery khác tại VietJack:
Dành cho bạn
Công cụ giáo viên
- Tạo đề online từ PDF / Word
- Trộn nhiều mã đề, in Offline
- Giao bài online, Quản lí lớp học

