jQuery 1.1 is reborn on its first birthday
Written by on January 15th, 2007 in Ajax News.
John Resig and team have released jQuery 1.1 which includes a speed upgrade, an updated API, a new homepage, and new documentation including a book in the works.
The community seems to be growing from strength to strength.
New Features
- By all of our counts, jQuery 1.1’s selectors are 10x-20x faster than those in jQuery 1.0.4. This should provide a noticable difference in your jQuery applications.
- Common selectors like div#id, div .class, td:nth-child(1), and div > div are all significantly faster. It’s a complete world of difference. Try them out and you’ll see.
- You can now pass in a function as a value for an attribute or a css property. The function is executed and its return value is set as the value for the property. For example:
// 1.0 Code $(\"a\").each(function(){ $(this).attr(\"href\", \"/item/\" + this.id); }).show(); // 1.1 Code $(\"a\").attr(\"href\", function(){ return \"/item/\" + this.id; }).show(); - You can now unbind an event handler from within itself. This allows you to have event handlers that are only bound for a specific number of executions, for example:
$(\"button\").click(function(e){ // Unbind the event handler if a specific form is hidden if ( $(\"#submitForm\").is(\":hidden\") ) { $(this).unbind( e ); } }); - Easily bind an event that will only occur once (this replaces the old .oneclick() functionality):
// Show a thank you message for a form submission, but only once $(\"form\").one(\"submit\",function(){ $(\"#thankyou\").show(); }); - You can now set the text value of an element (this is different from .html(), where in .text() all HTML is displayed as text).
$(\"pre\").text(\"<b>Hello</b>, how are you?\"); // Result: <pre><b>Hello</b>, how are you?</pre>
- You can now build your own filters, using a custom function. (This was in 1.0, but it wasn’t documented very well.)
// Find all divs whose parent isn't hidden $(\"div\").filter(function(){ return $(this).parent(\":hidden\").length > 0; }); - You can now pass a comma-separated list of selectors to the following filter functions:
filter, find, not, siblings, parents, children, next, prev. This allows you to do some very cool stuff:// Find all radio buttons, or checkboxes, in a form $(\"form input\").filter(\":radio, :checkbox\"); // Find the next element that's a span, or a div $(this).next(\"span, div\");
Source: Ajaxian
Original Article: http://ajaxian.com/archives/jquery-11-is-reborn-on-its-first-birthday