jQuery supports all major browsers, has a small file size, and is used by major websites such as Google! Here is the description from their website:
As described, jQuery does all the hard work with traversing the DOM, working with events, some nice animation effects, and AJAX functions. Things that would take several lines of JavaScript can be reduced to one line. Take this example where we change the font color in all div tags that do not have the "ignore" class:"jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development."
Code: Select all
// without jQuery
var divs = document.getElementsByTagName('div');
for(var i = 0; i < divs.length; i++) {
if(divs[i].className != 'ignore') {
divs[i].style.color = "#FF0000";
}
}
// with jQuery
$("div").not(".ignore").css('color', '#FF0000');
Code: Select all
// without jQuery
function getMenu(page, item) {
var HttpRequestObject = false;
if(window.XMLHttpRequest) {
HttpRequestObject = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
HttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
if(HttpRequestObject) {
var div = getElementById('target');
HttpRequestObject.open('GET', 'menu.php?page=' + page + '&item=' + item, true);
HttpRequestObject.onreadystatechange = function() {
if(HttpRequestObject.readyState == 4 && HttpRequestObject.status == 200) {
div.innerHTML = HttpRequestObject.responseText;
}
}
HttpRequestObject.send(null);
}
}
// with jQuery
function getMenu(page, item) {
$.get('menu.php', { 'page': page, 'item': item }, function(data) {
$("#target").text(data);
});
}
If you are a JavaScript coder and haven't yet checked out jQuery, it might be worth checking out!