1. What is jQuery?
a. A programming language
b. A JavaScript library
c. A markup language
d. An operating system
Answer: b. A JavaScript library
2. Which symbol is commonly used as a shortcut for jQuery?
a. $
b. #
c. *
d. &
Answer: a. $
3. Which jQuery method is used to toggle between hiding and showing an element?
a. toggle()
b. switch()
c. hideShow()
d. displayToggle()
Answer: a. toggle()
4. Which jQuery method is used to select elements based on their CSS attributes?
a. getElementById()
b. selectByClass()
c. findByAttribute()
d. find()
Answer: d. find()
5. What is the purpose of the $(document).ready() function in jQuery?
a. It initializes the jQuery library.
b. It waits for the entire document to load before executing code.
c. It triggers a document reload.
d. It defines a new document.
Answer: b. It waits for the entire document to load before executing code.
6. How do you select all elements with the class "example" in jQuery?
a. $(.example)
b. $("example")
c. $(".example")
d. #example
Answer: c. $(".example")
7. Which jQuery method is used to set the text of an element?
a. setText()
b. setInner()
c. text()
d. innerText()
Answer: c. text()
8. What is the purpose of the fadeIn() and fadeOut() methods in jQuery?
a. To add or remove elements from the page.
b. To hide and show elements with a fade-in/fade-out effect.
c. To rotate elements.
d. To resize elements.
Answer: b. To hide and show elements with a fade-in/fade-out effect.
9. How can you attach a click event to a button with the ID "myButton" in jQuery?
a. $("button#myButton").on("click", function() { })
b. $("myButton").click(function() { })
c. $("#myButton").on("click", function() { })
d. $("button").addEventListener("click", function() { })
Answer: c. $("#myButton").on("click", function() { })
10. Which jQuery method is used to make an AJAX request?
a. fetch()
b. ajax()
c. request()
d. getAjax()
Answer: b. ajax()
11. How can you prevent the default behavior of an anchor tag when it's clicked in jQuery?
a. event.preventDefault()
b. anchorTag.disable()
c. stopPropagation()
d. preventDefaultTag()
Answer: a. event.preventDefault()
12. What is the purpose of the animate() method in jQuery?
a. To play animated GIFs.
b. To animate elements over time.
c. To draw shapes on the canvas.
d. To change the page's background color.
Answer: b. To animate elements over time.
13. What does the $(element).html() method do in jQuery?
a. Retrieves the text of the element.
b. Sets the HTML content of an element.
c. Removes the element from the page.
d. Appends the element to another element.
Answer: b. Sets the HTML content of an element.
14. How can you select all input elements of type "text" in jQuery?
a. $("input[text]")
b. $("input[type='text']")
c. $("input:isText")
d. $("text")
Answer: b. $("input[type='text']")
15. Which jQuery method is used to remove elements from the DOM?
a. delete()
b. remove()
c. hide()
d. detach()
Answer: b. remove()
16. What is the purpose of the attr() method in jQuery?
a. To add a new attribute to an element.
b. To retrieve or set the value of an element's attribute.
c. To check if an element has a specific attribute.
d. To change an element's position.
Answer: b. To retrieve or set the value of an element's attribute.
17. How can you add a CSS class "highlight" to an element with ID "myElement" in jQuery?
a. $("#myElement").addClass("highlight");
b. $("#myElement").setAttribute("class", "highlight");
c. $("#myElement").style("highlight");
d. $("#myElement").addClassName("highlight");
Answer: a. $("#myElement").addClass("highlight");
18. Which jQuery method is used to set the value of an input element?
a. setValue()
b. value()
c. setInputValue()
d. val()
Answer: d. val()
19. How do you select the first element of a group of elements with the class "example" in jQuery?
a. $(".example:first")
b. $(".example[0]")
c. $(".example:first-child")
d. $(".example").first()
Answer: a. $(".example:first")
20. What is the purpose of the find() method in jQuery?
a. To create a new element.
b. To retrieve the first element that matches a selector within the selected element.
c. To hide elements.
d. To change the font size of an element.
Answer: b. To retrieve the first element that matches a selector within the selected element.
21. How do you stop an animation in progress using jQuery?
a. stopAnimation()
b. halt()
c. stop()
d. pause()
Answer: c. stop()
22. What is the purpose of the siblings() method in jQuery?
a. To select all elements that are siblings of the selected element.
b. To select child elements.
c. To select the parent element.
d. To select all elements on the page.
Answer: a. To select all elements that are siblings of the selected element.
23. Which jQuery method is used to set the CSS properties of an element?
a. css()
b. setStyle()
c. applyCSS()
d. changeStyle()
Answer: a. css()
24. How can you fade an element in over a duration of 2 seconds?
a. $("element").fadeIn(2000);
b. $("element").fadeIn("slow");
c. $("element").animate({ opacity: 1 }, 2000);
d. $("element").show(2000);
Answer: a. $("element").fadeIn(2000);
25. What does the slideDown() method do in jQuery?
a. Slides an element down
b. Hides an element
c. Animates an element's opacity
d. Shrinks an element
Answer: a. Slides an element down
26. How do you select all odd rows in a table using jQuery?
a. $("table tr:even")
b. $("table tr:odd")
c. $("table tr:nth-child(even)")
d. $("table tr:nth-child(odd)")
Answer: b. $("table tr:odd")
27. What is the purpose of the serialize() method in jQuery?
a. To convert an object to a string.
b. To convert a form's data into a query string.
c. To serialize an element's position.
d. To serialize an array.
Answer: b. To convert a form's data into a query string.
28. Which jQuery method is used to insert content at the beginning of an element?
a. prepend()
b. insertBefore()
c. before()
d. addBefore()
Answer: a. prepend()
29. How can you stop an event from bubbling up the DOM tree in jQuery?
a. stopPropagation()
b. preventDefault()
c. haltPropagation()
d. stopEvent()
Answer: a. stopPropagation()
30. What is the purpose of the empty() method in jQuery?
a. To remove all child elements from the selected element.
b. To hide the selected element.
c. To remove the selected element from the DOM.
d. To clear the contents of the selected element.
Answer: a. To remove all child elements from the selected element.
31. How can you set an attribute value using the attr() method in jQuery?
a. $(element).attr("attributeName", "value");
b. $(element).attr("value", "attributeName");
c. $(element).setAttribute("attributeName", "value");
d. $(element).value("attributeName", "value");
Answer: a. $(element).attr("attributeName", "value");
Top comments (0)