jQuery
The library that tamed cross-browser JavaScript. jQuery is still the most deployed JS library.
01jQuery Introduction & SelectorsjQuery Overview jQuery by John Resig (2006) made JavaScript accessible by simplifying DOM manipulation, event handling, and AJAX. <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> // or: npm install jquerycodequizbeginner
jQuery Overview jQuery by John Resig (2006) made JavaScript accessible by simplifying DOM manipulation, event handling, and AJAX. <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> // or: npm install jquery
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
// or: npm install jqueryWhat does $(document).ready() ensure?
Which jQuery selector finds elements with a specific ID?
jQuery's strength is:
02DOM Manipulation & EventsjQuery DOM & Events // Text $('#p1').text(); // get $('#p1').text('New text'); // set // HTML $('#div1').html(); // get inner HTML $('#div1').html('<b>Bold</b>'); // set inner HTML // Values (inputs) $('#input1').val(); // get $('#input1'codequizbeginner
jQuery DOM & Events // Text $('#p1').text(); // get $('#p1').text('New text'); // set // HTML $('#div1').html(); // get inner HTML $('#div1').html('<b>Bold</b>'); // set inner HTML // Values (inputs) $('#input1').val(); // get $('#input1'
// Text
$('#p1').text(); // get
$('#p1').text('New text'); // set
// HTML
$('#div1').html(); // get inner HTML
$('#div1').html('<b>Bold</b>'); // set inner HTML
// Values (inputs)
$('#input1').val(); // get
$('#input1').val('new value'); // set
// Attributes
$('img').attr('src'); // get
$('img').attr('src', 'new.jpg'); // set
$('a').removeAttr('href');
// CSS
$('#box').css('color'); // get
$('#box').css('color', 'red'); // set$("li").eq(2) returns:
Delegated events in jQuery (parent.on("click","li",fn)) are useful for:
$(this) inside a jQuery event handler refers to:
03AJAX & UtilitiesjQuery AJAX $.ajax({ url: '/api/users', method: 'GET', dataType: 'json', headers: { Authorization: 'Bearer token' }, success: (data) => console.log(data), error: (xhr, status, err) => console.error(err), complete: () => console.log('Done') });codequizintermediate
jQuery AJAX $.ajax({ url: '/api/users', method: 'GET', dataType: 'json', headers: { Authorization: 'Bearer token' }, success: (data) => console.log(data), error: (xhr, status, err) => console.error(err), complete: () => console.log('Done') });
$.ajax({
url: '/api/users',
method: 'GET',
dataType: 'json',
headers: { Authorization: 'Bearer token' },
success: (data) => console.log(data),
error: (xhr, status, err) => console.error(err),
complete: () => console.log('Done')
});Which jQuery method gets JSON data from a URL in one line?
$.grep() is similar to native JS:
$.extend({}, a, b) does what?