Basic jQuery Interview Questions
In this page:
jQuery क्या है?
jQuery एक JavaScript library है जो common DOM tasks को — elements select करना, बदलना, events handle करना, और animate करना — एक shorter, ज़्यादा।
उदाहरण: What is jQuery?
<!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
<!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
<!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
<!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
<!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>
- यह जवाब देना कि jQuery एक अलग language है, जबकि यह एक JavaScript library है।
$("#id")कोdocument.getElementById("id")से confuse करना, जबकि पहला methods वाला एक jQuery object return करता है और दूसरा एक plain DOM element।.click(fn)और.on("click", fn)को mix up करना और यह न जानना कि.on()delegation भी support करता है।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: