(5) JQuery Interview Questions and Answers

ans.

jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. Its advantages include:

  • Cross-browser compatibility: Helps write code that works consistently across different browsers.
  • Simplified DOM manipulation: Provides easy ways to manipulate HTML elements and attributes.
  • AJAX support: Simplifies asynchronous HTTP requests and responses.
  • Animation and effects: Provides methods to create animations and add visual effects easily.

ans.

 

  • Element selector: $("element")
  • Class selector: $(".class")
  • ID selector: $("#id")
  • Attribute selector: $("[attribute='value']")
  • Descendant selector: $("parent child")
  • Multiple selectors: $("selector1, selector2")

 

ans.

 

  • $(document).ready(function() { ... }): Executes when the DOM is fully loaded and ready to be manipulated, but before images and other external resources are fully loaded.

  • $(window).load(function() { ... }): Executes after the entire page, including all images and external resources, is fully loaded.

 

ans.

Events in jQuery are handled using the .on() method or shorthand methods like .click(), .hover(), etc.

$("#myButton").click(function() {
    // Handler code here
});

ans.

jQuery simplifies AJAX operations with methods like $.ajax(), $.get(), $.post()


$.ajax({
    url: "example.php",
    type: "GET",
    data: { param1: "value1", param2: "value2" },
    success: function(response) {
        // Handle successful response
    },
    error: function(xhr, status, error) {
        // Handle error
    }
});