-
Notifications
You must be signed in to change notification settings - Fork 47
jQuery
CORE uses jQuery extensively. It's essentially a de facto standard. It's not flawless and there are certainly other JavaScript frameworks out there, but most people who spend a lot of time with JavaScript are at least familiar with jQuery even if it isn't their personal favorite.
jQuery provides a lot in the way of cross-browser compatibility. It's an extremely powerful DOM manipulator and provides robust implementations of common functionality like AJAX calls or event handlers. It also tends to encourage a particular coding style which can be useful since JavaScript isn't the most structured language.
jQuery uses CSS selectors (and then some) to locate elements in the DOM.
var elem;
// vanilla javascript
elem = document.getElementById('main-table');
// jQuery
elem = $('#main-table');
// vanilla javascript
elem = document.getElementsByName('tr');
// jQuery
elem = $('tr');
// get rows from the main table with class special
elem = $('#main-table tr.special');For the first two functions jQuery is merely concise. The 3rd would be extremely unwieldy with plain JavaScript.
jQuery often uses getter and setter functions with identical names. The setter version takes an argument where as the getter does not. More equivalents:
var html;
// vanilla javascript
html = document.getElementById('main-table').html;
// jQuery
html = $('#main-table').html();
var new_value = '<tr></tr>';
// vanilla javascript
document.getElementById('main-table').html = new_value;
// jQuery
$('#main-table').html(new_value);Understanding the JavaScript syntax for objects and anonymous functions is useful as jQuery encourages the use of both.