JQuery MCQ(multiple choice question) with answer

In this jquery MCQ section, we will focus on the basic question which was asked in an interview, school or college exam, or during campus interviews.

1. jQuery is a

a) JSON library
b) JavaScript method
c) JavaScript library
d) java library

answer : c

Description : jQuery is a fast, small, cross-platform, and feature-rich JavaScript library.

2. which jquery method is used to hide selected elements?

a) hide() Method
b) display(none) method
c) Visible(True)
d) hidden()

answer : a

Description : The hide() method hides the selected elements.

3. jQuery uses ________ syntax to select elements

a) CSS
b) Javascript
c) HTML
d) Java

answer : a

Description : jQuery uses CSS syntax to select elements.

4. Which sign does jquery use as a shortcut for jquery?

a) & sign
b) % sign
c) @ sign
d) $ sign

answer : d

Description : $ sign is used as a shortcut for jQuery. Every jQuery selector starts with this dollar sign $().

5. Which jquery method is used to remove selected elements?

a) detach()
b) remove()
c) throw()
d) none of the above

answer : a

Description : The detach() method removes the selected elements

6. what is the correct jquery code to set the background color of all p elements to red?

a) $("p").display("background-color","red");
b) $("p").css("background-color","red");
c) $("p").layout("background-color","red");
d) $("p").style("background-color","red");

answer : b

Description : $("p").css("background-color","red"); is jquery code to set the background color of all p elements to red.

7. which jquery method returns the direct parent element of the selected element?

a) upperdiv() Method
b) parent() Method
c) divparent() Method
d) none of the above

answer : b

Description : The parent() method returns the direct parent element of the selected element.

8. with jquery, look at the following selector: $("div.intro"). what does it select?

a) All div elements with class="intro"
b) All div elements with id="intro"
c) The first div element with id="intro"
d) The first div element with class="intro"

answer : a

Description : All div elements with class="intro"

9. The jQuery html() method works for both HTML and XML documents

a) True
b) False
c) can't say
d) none of the above

answer : b

Description : JQuery HTML doesn’t work with XML document. It only works for HTML documents

10. which jquery method is used to set one or more style properties for selected elements?

a) css()
b) html()
c) style()
d) both style() and css()

answer : a

Description : css() method is used to set one or more style properties for selected elements in jquery

11. which jquery method should be used to deal with name conflicts?

a) The nameConflict() method
b) The noConflict() Method
c) The conflict() method
d) none of the above

answer : b

Description : The noConflict() Method should be used to deal with name conflicts. Javascript has many other frameworks which used $ sign. in case you use both jquery and other frameworks on the same page conflict will occur. To avoid this use noConflict() Method

12. when was jquery first released?

a) 2006
b) 2007
c) 2005
d) 2003

answer : a

Description : jquery first released in 2006

13. Which jQuery method is used to attach multiple event handlers to an element?

a) attach() method
b) unbind()
c) on()
d) click()

answer : c

Description : The on() method attaches one or more event handlers for the selected elements and child elements.

14. Which of the jQuery function prevents the code from running before the loading of the document finishes?

a) $(document).ready()
b) $(document).load()
c) $(document).trim()
d) $(document).unload()

answer : a

Description : $(document).ready() is to prevent any jQuery code from running before the document is finished loading.

15. What does the syntax $("p") will select?

a) Only first paragraph element
b) All paragraph elements
c) Only last paragraph
d) None of the above

answer : b

Description : it will select All paragraph elements

16. Which of the following is a single global function defined in the jQuery library?

a) jQuery()
b) $()
c) Queryanalysis()
d) global()

answer : a

Description : jQuery()

17. Look at the following selector: $("div"). What does it select?

a) All div element
b) first div element
c) last div element
d) none of the above

answer : a

Description : it will select All div element.

18. Which code will hide the current element?

a) $("p").hide()
b) $(this).hide()
c) $(this).hide('true');
d) $(this).hide(0);

answer : b

Description : $(this).hide()

19. jQuery is a ___________.

a) lightweight
b) heavyweight
c) Both A and B
d) none of the above

answer : a

Description : jQuery is a lightweight, "write less, do more", JavaScript library

20. $(this) in jQuery is used when

a) an HTML element references the action of its parent
b) an HTML element references the entire document
c) an HTML element references its own action
d) none of the above

answer : c

Description : an HTML element references its own action. $(this) represents a reference to the object that invoked the current function.

adsection