All jQuery Interview Questions
What is the difference between find() and children() in jQuery?
<div id="d"><ul><li>A</li><li>B</li></ul></div>
console.log($('#d').children().length);
console.log($('#d').find('li').length);
1
2
What is the difference between parent(), parents() and closest() in jQuery?
<div class="box"><ul><li><span id="s">x</span></li></ul></div>
console.log($('#s').parent().prop('tagName'));
console.log($('#s').parents().length);
console.log($('#s').closest('.box').prop('tagName'));
LI
5
DIV
What is the difference between append(), prepend(), after() and before()?
<ul id="l"><li>Middle</li></ul>
$('#l').append('<li>End</li>').prepend('<li>Start</li>');
$('#l').after('<p>After</p>').before('<p>Before</p>');
<p>Before</p>
<ul id="l">
<li>Start</li>
<li>Middle</li>
<li>End</li>
</ul>
<p>After</p>
See Add Elements.
How do you make an Ajax call in jQuery?
{ "status": "ok", "items": 3 }
<p>Page</p>
$.ajax({ url: 'data.json', dataType: 'json' })
.done(function (res) { console.log('Status: ' + res.status + ', items: ' + res.items); })
.fail(function () { console.log('Request failed'); });
Status: ok, items: 3
See jQuery Ajax.
What is the difference between $.get(), $.post() and $.ajax() in jQuery?
| Method | Use |
|---|---|
$.get(url, data, fn) | Quick GET request |
$.post(url, data, fn) | Quick POST request |
$.getJSON(url, fn) | GET request which expects JSON |
$.ajax({...}) | Any method (PUT, DELETE), headers, timeout, content type and more |
See jQuery Ajax.
How do you use the animate() method in jQuery?
<div id="box" style="width:100px;">Box</div>
$('#box').animate({ width: '+=100px', opacity: 0.5 }, 500, function () {
console.log('Done: ' + $(this).css('width'));
});
Done: 200px
Only numeric properties can be animated (colors need a plugin). See jQuery animate().
How do you check if an element exists in jQuery?
<p id="a">A</p>
console.log($('#a').length > 0);
console.log($('#missing').length > 0);
if ($('#missing').length) { console.log('found'); } else { console.log('not found'); }
true
false
not found
A selector which finds nothing returns an empty jQuery object, and the methods then do nothing. See jQuery Selectors.
What is the difference between this and $(this) in jQuery?
<button id="b" data-name="Save">Click</button>
$('#b').on('click', function () {
console.log(this.id); // DOM property
console.log($(this).data('name')); // jQuery method
console.log(this === $(this)[0]);
});
$('#b').click();
b
Save
true
How do you serialize a form in jQuery?
<form id="f"><input name="a" value="1"><input name="b" value="x y"></form>
console.log($('#f').serialize());
console.log($('#f').serializeArray());
a=1&b=x%20y
[ { name: 'a', value: '1' }, { name: 'b', value: 'x y' } ]
See jQuery Forms.
What is jQuery UI and how is it different from jQuery?
jQuery is the core library for the DOM, events, effects and Ajax. jQuery UI is an extra library which needs jQuery, and gives user interface parts: datepicker, dialog, accordion, tabs, sortable and draggable elements, and more effects and animations of colors. You load jQuery first, then jQuery UI. For new projects, many of these widgets are made today with plain HTML, CSS and JavaScript, or with other libraries.
What is the difference between jquery.js, jquery.min.js and the slim build?
| File | Meaning |
|---|---|
jquery.js | Full version with readable code, for learning and debugging |
jquery.min.js | Minified (smaller) version for the live site |
jquery.slim.js and .slim.min.js | Without Ajax and effects (and without Deferred in 4.0), smaller size |
If you need $.ajax() or .fadeIn(), do not use the slim file.
Is jQuery still relevant and should you learn it?
Yes, for a few reasons: a lot of existing websites, WordPress themes and plugins, and admin panels use jQuery, and a version 4.0 was released in January 2026, so it is still maintained. If you will work on real projects, you will meet it.
But for a new project, modern JavaScript can do most of the work, and frameworks like React and Vue are used for big applications. A good plan: learn JavaScript first, then learn jQuery to read and fix the existing code. See jQuery vs Vanilla JavaScript.
How do you check the jQuery version?
<p>Page</p>
console.log($.fn.jquery);
3.7.1
Run it in the console of your own page. The output above is from jQuery 3.7.1.
What is event delegation in jQuery and why is it useful?
<ul id="list"><li>A</li></ul>
$('#list').on('click', 'li', function () { console.log('clicked ' + $(this).text()); });
$('#list').append('<li>B</li>'); // added later
$('#list li').eq(1).click();
clicked B
It saves memory (one handler) and works for dynamic content. See Event Delegation.
What is the difference between bind(), live(), delegate() and on() in jQuery?
| Method | Status |
|---|---|
.bind(event, fn) | Deprecated since 3.0, use .on() |
.live() | Removed in jQuery 1.9, was the delegated version for the document |
.delegate(sel, event, fn) | Deprecated since 3.0, use .on(event, sel, fn) |
.on() | The one method to use for direct and delegated events |
<p>Page</p>
console.log('on: ' + typeof $.fn.on + ', live: ' + typeof $.fn.live);
on: function, live: undefined
What is a callback function in jQuery and why is it needed in effects?
<div id="b">Box</div>
$('#b').hide(300, function () {
console.log('2. callback: effect finished');
});
console.log('1. this runs immediately after starting the effect');
2. callback: effect finished
1. this runs immediately after starting the effect
What is the difference between stop(), finish() and delay() in jQuery?
| Method | Meaning |
|---|---|
.stop() | Stops the current animation where it is. .stop(true) also clears the queue |
.stop(true, true) | Clears the queue and jumps the current animation to its end |
.finish() | Jumps all queued animations of the element to their end values |
.delay(ms) | Waits before the next item of the queue |
Use .stop(true) before a hover animation, so quick hovering does not pile up animations. See jQuery animate().
What are Deferred objects and promises in jQuery?
{ "n": 1 }
{ "n": 2 }
<p>Page</p>
$.when($.getJSON('a.json'), $.getJSON('b.json')).done(function (a, b) {
console.log('Sum: ' + (a[0].n + b[0].n));
});
Sum: 3
How do you handle Ajax errors in jQuery?
<p>Page</p>
$.getJSON('missing.json')
.done(function () { console.log('ok'); })
.fail(function (xhr, status, error) {
console.log('Failed: ' + xhr.status + ' ' + error);
})
.always(function () { console.log('Request finished'); });
Failed: 404 Not Found
Request finished
Also set a timeout, show a message to the user and log the details. See jQuery Ajax.
How do you create a jQuery plugin?
<p class="a">One</p><p class="a">Two</p>
$.fn.markAs = function (options) {
var settings = $.extend({ label: 'done' }, options);
return this.each(function () {
$(this).addClass(settings.label);
});
};
$('.a').markAs({ label: 'checked' });
<p class="a checked">One</p>
<p class="a checked">Two</p>
See jQuery Plugins.
- « Previous
- 1
- 2
- 3
- Next »