← Back to jQuery Course | Chapter 16: jQuery vs Modern JS & Interview Prep | Lesson 5 of 6

Basic jQuery Interview Questions

jQuery एक JavaScript library है जो DOM manipulation, events, effects, और AJAX के लिए एक concise API देती है।

jQuery क्या है?

jQuery एक JavaScript library है जो common DOM tasks को — elements select करना, बदलना, events handle करना, और animate करना — एक shorter, ज़्यादा।

उदाहरण: What is jQuery?

javascript
<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  </head>
  <body>
    <p id="text">Text</p>
    <script>
      $("#text").css("color", "blue");
    </script>
  </body>
</html>

Selectors और DOM

Selectors वह तरीका हैं जिससे आप उन elements ढूँढते हैं जिनके साथ काम करना है, और jQuery का $() function CSS selectors जैसी same syntax accept करता है — ID, class, tag से।

उदाहरण: Selectors and DOM

javascript
<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  </head>
  <body>
    <p class="item">One</p>
    <script>
      console.log($(".item").length);
    </script>
  </body>
</html>

Events

jQuery .click() और .hover() जैसे dedicated event methods देता है, साथ ही किसी भी event type bind करने के लिए general-purpose .on() method, including।

उदाहरण: Events

javascript
<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  </head>
  <body>
    <button id="btn">Click</button>
    <script>
      $("#btn").on("click", function() {
      console.log("Clicked");
      });
    </script>
  </body>
</html>

Effects

jQuery में .hide(), .show(), .fadeIn(), और .slideDown() जैसे simple built-in effects शामिल हैं, जो बिना आपके किसी element की visibility या size को animate करते हैं।

उदाहरण: Effects

javascript
<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  </head>
  <body>
    <div id="box">Box</div>
    <button id="btn">Run Effect</button>
    <script>
      $("#btn").on("click", function() {
        $("#box").hide().fadeIn(500);
      });
    </script>
  </body>
</html>

AJAX

jQuery के AJAX methods page reload किए बिना server को asynchronous HTTP requests बनाते हैं। common shortcuts $.get() और $.post() दो को cover करते हैं।

उदाहरण: AJAX

javascript
<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  </head>
  <body>
    <script>
      $.get("data.php", function(data) { console.log(data); });
    </script>
  </body>
</html>
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह जवाब देना कि jQuery एक अलग language है, जबकि यह एक JavaScript library है।
  2. $("#id") को document.getElementById("id") से confuse करना, जबकि पहला methods वाला एक jQuery object return करता है और दूसरा एक plain DOM element।
  3. .click(fn) और .on("click", fn) को mix up करना और यह न जानना कि .on() delegation भी support करता है।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.