รูปแบบ syntax ดังนี้
โค้ด: เลือกทั้งหมด
$(selector).prepend(content, function)
content : เป็นพารามิเตอร์ที่จำเป็นซึ่งจะใช้ในการระบุเนื้อหาที่จะต้องการแทรก
function : มันเป็นพารามิเตอร์ตัวเลือกเพิ่มเติม(ไม่จำเป็น)ที่ใช้ในการระบุฟังก์ชั่นที่จะดำเนินการหลังจากเรียกใช้
การคืนค่า (Return Value) : วิธีนี้ส่งคืนelementที่เลือกพร้อมการเปลี่ยนแปลงที่กำหนดโดยวิธี prepend ()
ตัวอย่างโค้ดด้านล่างเป็นวิธีการ prepend () ใน jQuery:
โค้ด: เลือกทั้งหมด
<!DOCTYPE html>
<html>
<head>
<title>The prepend Method</title>
<script src="
https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<!-- jQuery code to show the woirking of this method -->
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").prepend("Welcome to ");
});
});
</script>
<style>
div {
width: 350px;
height: 100px;
font-weight: bold;
padding:20px;
font-size: 25px;
border: 2px solid navy;
}
</style>
</head>
<body>
<div>
<p>Mindphp!</p>
<!-- Click on this button to see the change -->
<button>Click Here!</button>
</div>
</body>
</html>
ช่องทางการศึกษาเพิ่มเติมข่าวที่น่าสนใจเกี่ยวกับ : jQuery
-สอนการใช้งาน HTML & CSS
-ถามตอบ HTML CSS
-บทเรียน CSS
-บทเรียน HTML5
-แลกเปลี่ยนความรู้ PHP