Example: Hide an Element
<!DOCTYPE html>
<html>
<head>
<title>jQuery Example</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<p id="text">Hello, this is jQuery!</p>
<button id="hideBtn">Hide Text</button>
<script>
$(document).ready(function(){
$("#hideBtn").click(function(){
$("#text").hide();
});
});
</script>
</body>
</html>
Explanation:
$(document).ready()→ Ensures code runs after the page loads.$("#hideBtn")→ Selects button by ID..click()→ Adds a click event.$("#text").hide()→ Hides the paragraph.
Leave a Reply