| jQuery 1.4.2 | YUI 3.3.0 | AUI 1.0.1 | Notes |
|---|---|---|---|
$.foo.bar() |
YUI().use('node', 'module2', 'module3', function (Y) {
Y.foo.bar()
});
|
AUI().use('node', 'module2', 'module3', function (A) {
A.foo.bar()
});
|
The
YUI3 is sandboxed and by default dynamically loaded. The
The return value of The return value of |
| jQuery 1.4.2 | YUI 3.3.0 | AUI 1.0.1 | Notes |
|---|---|---|---|
$('div.foo:first')
|
Y.one('div.foo')
|
A.one('div.foo')
|
jQuery, YUI3, & AUI use similar selector syntax, but jQuery has added extensions, mainly convenience pseudo-classes, to the Sizzle CSS3-compliant selector engine. YUI3 & AUI comes with three different selector engines; see the section on Selectors. |
var foo = $('div.foo:first');
foo.some_method();
|
var foo = Y.one('div.foo');
if (foo) {
foo.some_method();
}
|
var foo = A.one('div.foo');
if (foo) {
foo.some_method();
}
|
Return the first element which matches the selector. If no elements match,
|
$('div.foo')
|
Y.all('div.foo')
|
A.all('div.foo')
|
Select all div elements with a class of foo.
|
var foo = $('div.foo');
if (foo.length) {
// do something
}
|
var foo = Y.all('div.foo');
if (foo.size()) {
// do something
}
|
var foo = Y.all('div.foo');
if (foo.size()) {
// do something
}
|
If no elements match the selector,
|
.find('p.foo:first')
.find('p.foo')
|
.one('p.foo')
.all('p.foo')
|
.one('p.foo')
.all('p.foo')
|
Finds |
$('<div/>')
|
Y.Node.create('<div/>')
|
A.Node.create('<div/>')
|
Create a new DOM element. Does not add it to the document tree. |
.html('foo')
.text('foo')
.val('foo')
|
.setContent('foo')
.set('text', 'foo')
.set('value', 'foo')
|
.html('foo')
.text('foo')
.val('foo')
|
|
.html() .text() .val() |
.get('innerHTML')
.get('text')
.get('value')
|
.html() .text() .val() |
jQuery tends to overload getters and setters in the same method. |
.attr('foo')
.attr('foo', 'bar')
|
.getAttr('foo')
.setAttr('foo', 'bar')
|
.attr('foo')
.attr('foo', 'bar')
|
Generic HTML attribute getters and setters. |
.click(fn)
.focus(fn)
.blur(fn)
.mouseout(fn)
.mouseover(fn)
// jQuery 1.4.2 and later allows you to
// register events when creating the element
$('<p/>',{
text :'foo',
className : 'bar',
click : fn,
focus : fn,
blur : fn
})
|
.on('click', fn)
.on('focus', fn)
.on('blur', fn)
.on('mouseout', fn)
.on('mouseover', fn)
// Alternatively, YUI allows you to attach multiple
// subscribers with a single call.
.on({
click : fn,
focus : fn,
blur : fn,
mouseout : fn,
mouseover: fn
})
// Or attach a single subscriber to multiple events.
.on(['click', 'focus', 'blur', 'mouseout', 'mouseover'], fn)
|
.on('click', fn)
.on('focus', fn)
.on('blur', fn)
.on('mouseout', fn)
.on('mouseover', fn)
// Alternatively, AUI allows you to attach multiple
// subscribers with a single call.
.on({
click : fn,
focus : fn,
blur : fn,
mouseout : fn,
mouseover: fn
})
// Or attach a single subscriber to multiple events.
.on(['click', 'focus', 'blur', 'mouseout', 'mouseover'], fn)
|
|
parent.append('<div/>')
|
parent.append('<div/>')
|
parent.append('<div/>')
|
Creates a new div element and makes it a child of
|
child.appendTo(parent) |
child.appendTo(parent) |
child.appendTo(parent) |
Appends
|
parent = $('<div/>');
$('<p>foo<p>')
.click(fn)
.appendTo(parent);
|
parent = Y.Node.create('<div/>');
Y.Node.create('<p>foo</p>')
.appendTo(parent)
.on('click', fn);
|
parent = A.Node.create('<div/>');
A.Node.create('<p>foo</p>')
.appendTo(parent)
.on('click', fn);
|
Creates a new div element, then appends a p element with a click event subscription. Note that YUI's on() method is not chainable, so it returns an event handle, not the p node.
|
.empty() |
.empty(true) |
.empty() |
jQuery's
AUI removes the child (and other des) |
.siblings() .siblings(selector) |
.siblings() .siblings(selector) .siblings(function) |
.siblings()
.siblings(selector)
.siblings(function)
|
In addition to an optional selector string, YUI3 also supports passing a function to filter the returned siblings.
AUI supports passing a selector for the ancestors to be filtered on. If the reference node has no parent, then it does nothing. |
.show() .hide() |
.show() .hide() // If the transition module is loaded, // a fade transition will be used when // true is passed. .show(true) .hide(true) |
.show(); .hide(); // If the transition module is loaded, // a fade transition will be used when // true is passed. .show(true) .hide(true) |
In YUI,
AUI assume that your node was display/hidden based on the css class 'aui-helper-hidden' used. This won't manipulate the inline |
.before('foo')
.before('function')
.after('foo')
.after('function')
|
.insertBefore('foo')
.insertAfter('foo')
|
.placeBefore('foo')
.placeAfter('foo')
|
Add element before/after parent node as the next sibling.
If the reference node has no parent in AUI, it does nothing. |
| jQuery 1.4.2 | YUI 3.3.0 | AUI 1.0.1 | Notes |
|---|---|---|---|
$('*') |
Y.all('*') |
A.all('*') |
Select all nodes. Note that the default selector engine for YUI3 is CSS 2.1. For all examples in this section, use the |
$(':animated') |
Psuedoclass to select all elements currently being animated. No YUI3 equivalent. |
||
$(':button') |
Y.all('input[type=button], button') |
A.all(':button') |
Extension. In both jQuery and YUI3 you can run multiple selectors separated by commas. |
$(':checkbox') |
Y.all('input[type=checkbox]') |
A.all(':checkbox') |
Extension. |
$(':checked') |
Y.all(':checked') |
A.all(':checked') |
CSS3 |
$('parent > child') |
Y.all('parent > child') |
A.all('parent > child') |
Immediate child selector (child must be one level below parent) |
$('parent child') |
Y.all('parent child') |
A.all('parent child') |
Descendent selector (child can be at any level below parent) |
$('div.class') |
Y.all('div.class') |
A.all('div.class') |
Class selector |
$(":contains('foo')") |
Y.all(':contains(foo)') |
A.all(':contains(foo)') |
Extension to select all elements whose text matches 'foo'. jQuery can take quotes or not. YUI3 requires no quotes. The text matching is plain string comparison, not glob or regexp. Be careful with this one as it will return all matching ancestors, eg |
$(':disabled')
$(':enabled')
|
Y.all(':disabled')
Y.all(':enabled')
|
A.all(':disabled')
A.all(':enabled')
|
CSS3. |
$(':empty') |
Y.all(':empty') |
A.all(':empty') |
CSS3. Selects all elements that have no child nodes (excluding text nodes). |
$(':parent') |
Y.all(':not(:empty)') |
A.all(':parent')
A.all(':not(:empty)')
|
Inverse of |
$('div:eq(n)') |
Y.all('div').item(n) |
A.all('div').item(n) |
Extension. Selects nth element. YUI's |
$('div:even')
$('div:odd')
|
Y.all('div').even()
Y.all('div').odd()
|
A.all('div').even()
A.all('div').odd()
|
Extension. Selects all even or odd elements. Note that elements are 0-indexed and the 0th element is considered even. See also YUI3's |
$(':file') |
Y.all('input[type=file]') |
A.all(':file')
|
Extension. Find input elements whose |
$('div:first-child') |
Y.all('div:first-child') |
A.all('div:first-child') |
CSS3. Selects the first child element of divs. |
$('div:first) |
Y.one('div') |
A.one('div') |
The |
$('div:gt(n)');
$('div:lt(n)');
// or
$('div').slice(n + 1);
$('div').slice(0,n);
|
Y.all('div').slice(n + 1);
Y.all('div').slice(0, n);
|
A.all('div').slice(n + 1);
A.all('div').slice(0, n);
|
Extension. |
$('div:has(p)') |
var nodes = [];
Y.all('div').each(function (node) {
if (node.one('p')) {
nodes.push(node);
}
});
nodes = Y.all(nodes);
|
var nodes = [];
A.all('div').each(function (node) {
if (node.one('p')) {
nodes.push(node);
}
});
nodes = A.all(nodes);
|
Extension. Selects elements which contain at least one element that matches the specified selector. In this example, all |
$(':header') |
Y.all('h1,h2,h3,h4,h5,h6') |
A.all(':header') |
Extension. Selects all heading elements. Rarely used. |
$('div:hidden') |
var hidden = [];
Y.all('div').each(function(node) {
if ((node.get('offsetWidth') === 0 &&
node.get('offsetHeight') === 0) ||
node.get('display') === 'none') {
hidden.push(node);
}
});
hidden = Y.all(hidden);
|
A.all(':hidden')
|
Extension. In jQuery > 1.3.2 The YUI3 equivalent would essentially be a port of the jQuery code that implements |
$('#id') |
Y.all('#id') |
A.all('#id') |
CSS3. Identity selector. |
$('input:image') |
Y.all('input[type=image]') |
A.all(':image')
|
Extension. Selects all inputs of type image. |
$(':input') |
Y.all('input,textarea,select,button') |
A.all(':input')
|
Extension. Selects all user-editable form elements. |
$(':last-child') |
Y.all(':last-child') |
A.all(':last-child') |
CSS3. |
$('div:last') |
var list = Y.all('div'),
last;
if (list.size()) {
last = list.item(list.size() - 1);
}
|
var list = A.all('div'),
last;
if (list.size()) {
last = list.item(list.size() - 1);
}
|
Extension. Selects the last element matched by the selector. |
$('input[type=checkbox][checked]') |
Y.all('input[type=checkbox][checked]') |
A.all(':checkbox:checked') |
CSS3, multiple attribute selector |
$(':not(div)') |
Y.all(':not(div)') |
A.all(':not(div)') |
CSS3. Negation selector. |
$(':password') |
Y.all('input[type=password]') |
A.all(':password')
|
Extension. |
$(':radio') |
Y.all('input[type=radio]') |
A.all(':radio')
|
Extension. |
$(':reset') |
Y.all('input[type=reset]') |
A.all(':reset')
|
Extension. |
$(':selected') |
Y.all('option[selected]') |
A.all(':selected')
|
Extension. |
$(':submit') |
Y.all('input[type=submit]') |
A.all(':submit')
|
Extension. |
$(':text') |
Y.all('input[type=text]') |
A.all(':text')
|
Extension. Does not select |
| jQuery 1.4.2 | YUI 3.3.0 | AUI 1.0.1 | Notes |
|---|---|---|---|
$('#foo').animate(
{
width: 100,
height: 100,
opacity: 0.5
},
{
duration: 600,
easing: 'swing'
}
);
|
var a = new Y.Anim(
{
node: '#foo',
to: {
width: 100,
height: 100,
opacity: 0.5
},
duration: 0.6,
easing: Y.Easing.bounceOut
}
);
a.run();
|
var a = new A.Anim(
{
node: '#foo',
to: {
width: 100,
height: 100,
opacity: 0.5
},
duration: 0.6,
easing: A.Easing.bounceOut
}
);
a.run();
//or
A=AUI().use('transition');
A.one('#foo').transition({
width: 100,
height: 100,
opacity: 0.5,
duration: 0.6
})
|
The basic syntax and capabilities of both animation libraries are very similar. jQuery has convenience methods for effects like YUI3 has several easing algorithms built-in, and offers additional tools such as animations over Bezier curves. Make sure to load the AUI's |
$('#.foo').fadeOut();
// or
$('#.foo').hide(600);
|
Y.one('#foo').hide(true)
|
A.one('#foo').hide(true)
// or
A=AUI().use('transition');
A.one('#foo').transition({
opacity: 0,
duration: 0.6
})
|
jQuery's jQuery effects tend to default to 200 or 600ms while YUI's show/hide transitions default to 500ms. YUI durations are in fractions of seconds; jQuery durations are set in milliseconds. AUI's |
| jQuery 1.4.2 | YUI 3.3.0 | AUI 1.0.1 | Notes |
|---|---|---|---|
$('.foo').array_method(args) |
Y.all('.foo').array_method(args) |
A.all('.foo').array_method(args) |
Any Array operation that you can perform on a jQuery list can be translated to YUI in this form. YUI NodeList objects are not native Arrays, but do provide wrapper functions for the most common array methods as of 3.3.0. |
$('div').slice(x, y) |
Y.all('div').slice(x, y) |
A.all('div').slice(x, y) |
Return the xth to the yth div elements. |
$('div').add('p') |
Y.all('div').concat(Y.all('p')); |
Add nodes that match the specified selector. |
|
$('.foo').each(
function() {
this.some_method();
}
);
|
Y.all('.foo').each(
function() {
this.some_method();
}
);
|
A.all('.foo').each(
function() {
this.some_method();
}
);
|
|
$('.foo').filter('.bar') |
Y.all('.foo').filter('.bar') |
A.all('.foo').filter('.bar') |
The |
var fn = function(idx) {
return this.property === 'value';
};
$('.foo').filter(fn);
|
var filtered = [];
Y.all('.foo').each(
function(node) {
if (node.get('property') === 'value') {
filtered.push(node);
}
}
);
filtered = Y.all(filtered);
|
var filtered = [];
A.all('.foo').each(
function(node) {
if (node.get('property') === 'value') {
filtered.push(node);
}
}
);
filtered = A.all(filtered);
// or
A=AUI().use('array-extras');
var n = A.all('foo');
var filtered = A.Array.filter(n.getDOM(), function(item, index, collection){
return item.get('property') == 'value');
});
A.all(filtered);
|
Classic functional programming filter function. Given a list of elements, run the function on each and return a list of those which evaluated true. AUI |
$('.foo').map(
function(idx, el) {
some_function(el);
}
).get();
|
var mapped = [];
Y.all('.foo').each(
function(node) {
mapped.push(
some_function(node)
);
}
);
mapped = Y.all(mapped);
|
var mapped = [];
A.all('.foo').each(
function(node) {
mapped.push(
some_function(node)
);
}
);
mapped = A.all(mapped);
// or
A=AUI().use('array-extras');
var n = A.all('foo');
var map = A.Array.map(n.getDOM(), function(item, index, collection){
return some_function(item);
});
A.all(map);
|
jQuery's AUI |
| jQuery 1.4.2 | YUI 3.3.0 | AUI 1.0.1 | Notes |
|---|---|---|---|
$.ajax({
url: url,
data: data,
success: successFn
});
|
Y.io(url, {
data: data,
on: {success: successFn}
});
|
A.io.request(url, {
method: method,
dataType: data,
on: {success: successFn}
});
|
YUI.io & AUI have extra options for failure mode callbacks, headers, cross-frame i/o, etc. jQuery.ajax() has some interesting options for async, context, and filtering. Make sure to load the YUI AUI |
Y.io(url, {
data: data,
on: {success: successFn},
xdr: {use: 'flash'}
});
|
A.io.request(url, {
method: method,
data: data,
on: {success: successFn},
xdr: {use: 'flash'}
})
|
Cross-domain requests via a Flash helper. No jQuery equivalent. AUI |
|
$('#message').load('url'); |
Y.one('#message').load('url');
Y.one('#message').load('url', '#foo');
|
A.one('#message').load('url');
A.one('#message').load('url', '#foo');
// or
A.one('#message').plug(A.Plugin.IO, {
uri: 'url',
method: 'method'
});
|
Load the content of a given URL and replace the contents of In YUI, the AUI |
| jQuery 1.4.2 | YUI 3.3.0 | AUI 1.0.1 | Notes |
|---|---|---|---|
.addClass('foo')
.removeClass('foo')
.toggleClass('foo')
.hasClass('foo')
|
.addClass('foo')
.removeClass('foo')
.toggleClass('foo')
.hasClass('foo')
|
.addClass('foo')
.removeClass('foo')
.toggleClass('foo')
.hasClass('foo')
|
CSS class name manipulation. |
.removeClass('foo').addClass('bar') |
.replaceClass('foo', 'bar') |
.replaceClass('foo', 'bar') |
Replace node's CSS class 'foo' with 'bar'. |
.css('display', 'block') |
.setStyle('display', 'block') |
.setStyle('display', 'block') |
Set a single CSS property |
.css({
height: 100,
width: 100,
display: 'block'
})
|
.setStyles({
height: 100,
width: 100,
display: 'block'
})
|
.setStyles({
height: 100,
width: 100,
display: 'block'
})
|
Set multiple CSS properties with a dictionary. |
.css('display') |
.getStyle('display') |
.getStyle('display') |
Get the current value for a CSS property. |
.height() .width() |
??? |
get('offsetWidth') - getPadding('lr') - getBorderWidth('lr') |
Computed height / width. Excludes padding and borders. AUI getBorderWidth has values of t(top), l(left), r(right), b(bottom) |
.innerHeight() .innerWidth() |
??? |
get('offsetWidth') - getBorderWidth('lr') |
Includes padding but not border AUI getBorderWidth has values of t(top), l(left), r(right), b(bottom) |
.outerHeight() .outerWidth() |
.get('offsetHeight')
.get('offsetWidth')
|
.get('offsetHeight')
.get('offsetWidth')
|
Includes padding and border |
.position()
// {left: 123, top: 456}
|
.getXY() // [123, 456] |
.getXY() // [123, 456] |
Get the computed x,y coordinates. In jQuery, the coordinates are relative to the nearest ancestor element that is relatively or absolutely positioned. In YUI, they're relative to the document. |
The jQuery - YUI3 Rosetta Stone was originally created by Carlos Bueno. It's now maintained by the YUI team and Paul Irish.
Please file bugs and recommend changes on GitHub. You're also more than welcome to fork the GitHub repo and send pull requests.