jQuery_Exam_Answers_Final
jQuery_Exam_Answers_Final
- JavaScript: Since jQuery is a JavaScript library, knowing JavaScript fundamentals like variables,
jQuery selectors are used to select and manipulate HTML elements. They allow you to apply
Example:
$("p").css("color", "red");
4. What is an event in jQuery?
Example:
$("#myButton").click(function() {
alert("Button clicked!");
});
5. What is traversing?
Traversing in jQuery allows navigation through elements in the DOM tree. It helps to find elements
relative to another.
Example:
Example:
$("#myDiv").remove();
1. Write a jQuery code to check whether the page scrolls from bottom to top and vice versa.
$(window).scroll(function () {
console.log("Scrolling Down");
} else {
console.log("Scrolling Up");
});
e.preventDefault();
});
$(document).ready(function () {
return false;
});
});
4. Write a jQuery code to check whether jQuery is loaded or not.
if (window.jQuery) {
console.log("jQuery is loaded.");
} else {
$("img").on("error", function () {
$(this).attr("src", "default.jpg");
});
$("a").click(function (e) {
e.preventDefault();
});
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
$("#btn").click(function() {
alert("Button Clicked!");
});
- hover() Event: Triggers two functions when the mouse enters and leaves an element.
$("#box").hover(
);
$("#box").fadeIn(1000);
$("#box").fadeOut(1000);
$("#box").fadeToggle(1000);
$("#box").fadeTo(1000, 0.5);