Search Tutorials


jQuery MCQ Questions and Answers | JavaInUse

jQuery MCQ Questions and Answers

Q. What is jQuery used for?

A. Simplifying HTML document traversal and manipulation
B. Sending data to a server using AJAX
C. Both A and B
D. Neither A nor B

Q. How do you select elements using jQuery?

A. By using the $() function
B. By using the jQuery() function
C. By using the select() method
D. By using the find() method

Q. What is the purpose of the .css() method in jQuery?

A. To get the value of a CSS property
B. To set the value of a CSS property
C. Both A and B
D. Neither A nor B

Q. How do you add an event handler to an element using jQuery?

A. By using the .on() method
B. By using the .bind() method
C. By using the .click() method
D. By using the .event() method

Q. What is the purpose of the .each() method in jQuery?

A. To iterate over a jQuery object
B. To iterate over an array
C. To iterate over a set of elements
D. All of the above

Q. How do you create a jQuery plugin?

A. By extending the jQuery object
B. By using the .plugin() method
C. By creating a new function that takes a jQuery object as an argument
D. By using the $().plugin() syntax

Q. What is the purpose of the .ajax() method in jQuery?

A. To perform an AJAX request
B. To handle server responses
C. To send data to a server
D. All of the above

Q. How do you check if an element exists using jQuery?

A. By using the .exists() method
B. By using the .is() method
C. By using the .length property
D. By using the .visible() method

Q. What is the purpose of the .fadeIn() and .fadeOut() methods in jQuery?

A. To fade in and out an element with a smooth transition
B. To toggle the visibility of an element
C. To change the opacity of an element
D. To slide an element up and down





Q. How do you get the value of an attribute using jQuery?

A. By using the .attr() method
B. By using the .get() method
C. By using the .val() method
D. By using the .value() method

Q. What is the purpose of the .promise() method in jQuery?

A. To create a new Promise object
B. To convert a jQuery object to a Promise
C. To handle asynchronous operations
D. To synchronize AJAX requests

Q. How do you create a jQuery selector for elements with a specific class?

A. By using a dot followed by the class name
B. By using a hash followed by the class name
C. By using a colon followed by the class name
D. By using a semicolon followed by the class name

Q. What is the purpose of the .data() method in jQuery?

A. To store arbitrary data associated with DOM elements
B. To retrieve data associated with DOM elements
C. Both A and B
D. Neither A nor B

Q. How do you remove elements from the DOM using jQuery?

A. By using the .remove() method
B. By using the .delete() method
C. By using the .removeElement() method
D. By using the .destroy() method

Q. What is the purpose of the .animate() method in jQuery?

A. To create custom animations
B. To change the CSS properties of an element over time
C. To add or remove classes over time
D. All of the above

Q. Which of the following jQuery code snippets correctly selects all the paragraphs inside a div with the class "content" and applies a CSS style to make the text red?

A.
$("div.content p").css("color", "red");
B.
$("#content p").css({ color: "red" });
C.
$(".content").find("p").css("color", red);
D.
$("div.content").children("p").css({ color: red });

Q. What will be the output of the following jQuery code snippet?

let number = 5;
if (number % 2 === 0) {
    $("#result").html("Even");
} else {
    $("#result").html("Odd");
}
A.
Even
B.
Odd
C.
undefined
D.
Syntax error

Q. Which of the following jQuery code snippets correctly adds a click event handler to all buttons with the class "btn"?

A.
$(".btn").on("click", function() {
    // code to execute when button is clicked
});
B.
$("button.btn").click(function() {
    // code to execute when button is clicked
});
C.
$(".btn").click(function() {
    // code to execute when button is clicked
});
D.
$("button.btn").on("click", function() {
    // code to execute on button click
});

Q. What will be the output of the following jQuery code snippet?

let myArray = ["apple", "banana", "cherry"];
let result = myArray.join(", ");
$("#result").html(result);
A.
apple, banana, cherry
B.
apple banana cherry
C.
[apple, banana, cherry]
D.
Syntax error

Q. Which of the following jQuery code snippets correctly hides all elements with the class "hidden"?

A.
$(".hidden").hide();
B.
$("hidden").hide();
C.
$(".hidden").css("display", "none");
D.
$("hidden").css({ display: "none" });

Q. What will be the output of the following jQuery code snippet?

let myObj = {
    name: "John",
    age: 30
};
let result = myObj.name.toUpperCase();
$("#result").html(result);
A.
JOHN
B.
john
C.
30
D.
Syntax error

Q. Which of the following jQuery code snippets correctly checks if a checkbox with the ID "myCheckbox" is checked?

A.
if ($("#myCheckbox").is(":checked")) {
    // checkbox is checked
}
B.
if ($("#myCheckbox").prop("checked")) {
    // checkbox is checked
}
C.
if ($("#myCheckbox:checked")) {
    // checkbox is checked
}
D.
if ($("#myCheckbox").checked) {
    // checkbox is checked
}

Q. What will be the output of the following jQuery code snippet?

let myArray = [1, 2, 3, 4, 5];
let result = myArray.slice(1, 3);
$("#result").html(result);
A.
[2, 3]
B.
2, 3
C.
[1, 2, 3, 4]
D.
Syntax error

Q. Which of the following jQuery code snippets correctly adds a new div element with the class "newDiv" after the element with the ID "target"?

A.
$(#target).after("<div class='newDiv'></div>");
B.
$(.target).after("<div class='newDiv'></div>");
C.
$(#target).append("<div class='newDiv'></div>");
D.
$(.target).append("<div class='newDiv'></div>");

Q. What will be the output of the following jQuery code snippet?

let myString = "Hello, World!";
let result = myString.substring(0, 5);
$("#result").html(result);
A.
Hello
B.
Hello,
C.
World!
D.
Syntax error