1. What is jQuery?

Answer: jQuery is a fast, small, and feature-rich JavaScript library. It simplifies HTML document traversal, manipulation, event handling, animation, and Ajax.

$(document).ready(function(){

alert("DOM is ready!");

});

2. How to include jQuery in a project?

Answer: Use CDN or download the file.

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

3. What does $() do in jQuery?

Answer: It’s a shorthand for jQuery() and is used to select DOM elements.

$("#myDiv").hide();

4. Difference between $(document).ready() and window.onload?

Answer:

  • $(document).ready() triggers when the DOM is fully loaded.

  • window.onload waits for images and iframes too.

5. How do you select elements by ID, class, and tag?

$("#id"); // By ID

$(".class"); // By class

$("div"); // By tag

6. What is the difference between $(this) and this in jQuery?

Answer: $(this) is a jQuery object, this is a raw DOM element.

$(this).hide(); // jQuery

this.style.display = 'none'; // Vanilla JS

7. How to select all elements with a specific attribute?

$("[href]") // selects all elements with href attribute

8. How to traverse the DOM using jQuery?

$("#myDiv").parent().css("color", "red");

9. What is the difference between .find() and .children()?

  • .children() finds immediate children only.

  • .find() searches all descendants.

10. How to filter elements using jQuery?

$("li").filter(".active").css("color", "green");