Home Page https://jquery.com/
ใช้งานฟังก์ชัน ready
เมื่อคลิกที่ tag a แล้วจะแสดง Alert

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a").click(function(){
alert("Hello World!");
});
});
</script>
</head>
<body>
<a href="#">Click Me!</a>
</body>
</html>
เมื่อคลิกที่ tag p แล้วข้อความจะหายไป (tag p หาย)
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
</body>
</html>
เมื่อคลิกที่ tag p แล้วเปลี่ยนสี background (เรียกใช้ css)
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).css("background-color", "#ccffcc");
});
});
</script>
</head>
<body>
<p>Change background color</p>
</body>
</html>
Link
- jQuery Tutorial https://www.w3schools.com/jquery/