jQuery 1.6.1 Released

Posted on by

We’re pleased to announce the first update to jQuery 1.6!

You can get the code from the jQuery CDN:

Additionally you can also load the URLs directly from Microsoft and Google’s CDNs:

Microsoft CDN: http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js
Google CDN: https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js

You can help us by dropping that code into your existing application and letting us know that if anything no longer works. Please file a bug and be sure to mention that you’re testing against jQuery 1.6.1.

We want to encourage everyone from the community to try and get involved in contributing back to jQuery core. We’ve set up a full page of information dedicated towards becoming more involved with the team. The team is here and ready to help you help us!

Upgrading From 1.5.2 to 1.6.1

With the introduction of the new .prop() method and the changes to the .attr() method, jQuery 1.6 sparked a discussion about the difference between attributes and properties and how they relate to each other. It also came with some backwards compatibility issues that have been fixed in 1.6.1. When updating from 1.5.2 to 1.6.1, you should not have to change any attribute code.

Below is a description of the changes to the Attributes module in jQuery 1.6 and 1.6.1, as well as the preferred usage of the .attr() method and the .prop() method. However, as previously stated, jQuery 1.6.1 will allow you to use .attr() just as it was used before in all situations.

Note that the changes described in the 1.6 release notes regarding the .data() method have been worked around and now work seamlessly between 1.5.2 and 1.6.1.

What’s Changed

The changes to the Attributes module removed the ambiguity between attributes and properties, but caused some confusion in the jQuery community, since all versions of jQuery prior to 1.6 have handled attributes and properties in one method(.attr()). The old .attr() method had many bugs and was hard to maintain.

jQuery 1.6.1 comes with several bug fixes as well as an update to the Attributes module.

Specifically, boolean attributes such as checked, selected, readonly, and disabled in 1.6.1 will be treated just as they used to be treated in jQuery versions prior to 1.6. This means that code such as

$(“:checkbox”).attr(“checked”, true);
$(“option”).attr(“selected”, true);
$(“input”).attr(“readonly”, true);
$(“input”).attr(“disabled”, true);

or even:

if ( $(“:checkbox”).attr(“checked”) ) { /* Do something */ }

will not need to be changed in 1.6.1 in order to work as previously expected.

To make the changes to .attr() in jQuery 1.6 clear, here are some examples of the use cases of .attr() that worked in previous versions of jQuery that should be switched to use .prop() instead:

.attr() Proper .prop() usage
$(window).attr… $(window).prop…
$(document).attr… $(document).prop…
$(“:checkbox”).attr(“checked”, true); $(“:checkbox”).prop(“checked”, true);
$(“option”).attr(“selected”, true); $(“option”).prop(“selected”, true);

First, using the .attr() method on the window or document did not work in jQuery 1.6 because the window and document cannot have attributes. They contain properties (such as location or readyState) that should be manipulated with .prop() or simply with raw javascript. In jQuery 1.6.1, the .attr() will defer to the .prop() method for both the window and document instead of throwing an error.

Next, checked, selected, and other boolean attributes previously mentioned are receiving special treatment because of the special relationship between these attributes and their corresponding properties. Basically, an attribute is what you see in the html:

<input type=”checkbox” checked=”checked”>

Boolean attributes such as checked only set the default or initial value. In the case of a checkbox, the checked attribute sets whether the checkbox should be checked when the page loads.

Properties are what the browser uses to keep track of the current values. Normally, properties reflect their corresponding attributes (if they exist). This is not the case with boolean attributes. Boolean properties stay up to date when the user clicks a checkbox or selects an option in a select element. The corresponding boolean attributes do not. As was stated above, they are used by the browser only to store the initial value.

$(“:checkbox”).get(0).checked = true;
// Is the same as $(":checkbox:first").prop(“checked”, true);

In jQuery 1.6, setting checked with

$(“:checkbox”).attr(“checked”, true);

would not check the checkbox because it was the property that needed to be set and all you were setting was the initial value.

However, once jQuery 1.6 was released, the jQuery team understood that it was not particularly useful to set something that the browser was only concerned with on page load. Therefore, in the interest of backwards compatibility and the usefulness of the .attr() method, we will continue to be able to get and set these boolean attributes with the .attr() method in jQuery 1.6.1.

The most common boolean attributes are checked, selected, disabled, and readOnly, but here is a full list of boolean attributes/properties that jQuery 1.6.1 supports dynamically getting and setting with .attr():

autofocus, autoplay, async, checked, controls, defer, disabled,
hidden, loop, multiple, open, readonly, required, scoped, selected

It is still recommended that .prop() be used when setting these boolean attributes/properties, but your code will continue working in jQuery 1.6.1 even if these use cases are not switched to use the .prop() method.

Below is a list of some attributes and properties and which method should normally be used when getting or setting them. This is the preferred usage, but the .attr() method will work in all attribute cases.

Note that some DOM Element properties are also listed below – but will only work with the new .prop() method.

Attribute/Property .attr() .prop()
accesskey
align
async
autofocus
checked
class
contenteditable
defaultValue
draggable
href
id
label
location *
multiple
nodeName
nodeType
readOnly
rel
selected
selectedIndex
src
style
tabindex
tagName
title
type
width **

* For example, with window.location
** If needed over .width()

Neither .attr() nor .prop() should be used for getting/setting value. Use the .val() method instead (although using .attr(“value”, “somevalue”) will continue to work, as it did before 1.6).

Summary of Preferred Usage

The .prop() method should be used for boolean attributes/properties and for properties which do not exist in html (such as window.location). All other attributes (ones you can see in the html) can and should continue to be manipulated with the .attr() method.

jQuery 1.6.1 Change Log

The current change log of the 1.6.1 release.

Attributes

  • #9071: $(‘<option></option>’).val(‘myValue’) no longer sets value
  • #9079: .attr(“selected”) returns non-useful value in 1.6
  • #9089: 1.6 atrr() Inconsistant in IE7,8
  • #9094: Issue with jQuery 1.6: Can’t uncheck checkboxes
  • #9103: .attr(‘foo’, true) not setting related DOM property
  • #9123: Strange behavior of attr method when generate input element.
  • #9129: jQuery does not support enumerated attributes such as contenteditable
  • #9191: attr checked bug on radio

Data

  • #9124: Changes to $.data illogical in certain case
  • #9126: jquery breaks on use strict

Deferred

  • #9104: Returning null or undefined in a pipe filter function causes an exception

Effects

  • #9074: Cannot animate position and opacity at same time
  • #9100: Order of hide() callbacks has changed

Event

  • #9069: when hover over a child of an element, mouseleave fires when using live or delegate

Manipulation

  • #9072: jQuery 1.6 Crashes IE 6
  • #9221: Javascript within AJAX fails to load in IE – Error 80020101

Queue

  • #9147: Variable tmp in promise implicitly declared?

Selector

  • #7341: Slow .add() in IE
  • #9096: Selector or find bug in jQuery 1.6
  • #9154: :reset pseudo-selector broken

Support

  • #8763: Unhandled exception: document.defaultView.getComputedStyle(div, null) is null (FF, hidden iframe)
  • #9109: support.boxModel now false in IE6 even when not in quirks mode

60 thoughts on “jQuery 1.6.1 Released

  1. penuel on said:

    please im a bit new to this could you please tell me about jquery and how it could be of help

  2. TonyR on said:

    You say “Neither .attr() nor .prop() should be used for getting/setting value. Use the .val() method instead (although using .attr(“value”, “somevalue”) will continue to work, as it did before 1.6).” However when I try to use the val() method like so $(“#subscribe:checked”).val(false) it doesn’t work – it returns “undefined” so how should I be using this? The pre-1.6 method works just fine.

  3. @TonyR,
    element Value is something else then it’s property or attribute’s value.
    When you want to uncheck a checkbox, you want to remove the checked property so use $(“#subscribe:checked”).prop(“checked”, false);

  4. Klaas on said:

    Hi,

    did you change any issues regarding the caching and forward-backward in browser? I had problems when navigation between two pages and hitting the back button. I did ajax and DOM manipulation on page1.html, jumped to page2.html and when hitting the back button, the page was normally loaded again. No it seems that jquery goes back to page one without reloading and just displays the page from cache(no alert is thrown in window.load after going on page1.html via back button and it scrolls to the correct position).

    I did not see anything in the changelog, but it would be great to know if something has changed. I will also check if it might be any code changes I have done.

    cheers,
    klaas

  5. What is with the prop and attr separation from the usage point of view, how does having two separate things for the same goal make my life easier?…

  6. Hola, yo estuve trabajando con jquery-1.4.2.js y nunca más la actualice porque tenía problemas con el JQuery autocomplete.
    Si bien la lista me la muestra bien, me gustaría saber como puede hacer para que me busque (en el autocomplete) por carácter ingresado, como tengo ahora en mi sitio (http://www.glosarioit.com, que quiero actualizar con la versión jquery-1-6-1), y no que si se ingresa “ar” me muestre “Adware,AppleShare,etc.”, sino que salga “Arrays, ARPA, etc.”, o sea, que tenga en cuenta los primeros caracteres de la palabra y no si están en el medio o final.
    Además también quisiera, que me liste términos con o sin acentos por igual (se que en inglés no se usa, pero si en español).
    Espero se entienda mi idea.

  7. Hi, I was working with jquery-1.4.2.js and never update it because I had problems with the jQuery autocomplete.
    While the list shows me well, I wonder how you can do to make me look (in the autocomplete) for character input, as I have now on my site (http://www.glosarioit.com, I want to update with jquery version-1-6-1), than if you enter “ar” show me “Adware, AppleShare, and so on.” but leave “Arrays, ARPA, etc..” ie, taking into account first characters of the word and not if they are in the middle or end.
    In addition I would also like that I list with or without accents terms equally (which in English is not used, but in Spanish).
    Apologize for my English and I hope you understand my idea.

  8. Larry A on said:

    Hi!

    Version of 1.6.1 immediatelly gave me problems with something that previously worked on IE8.

    If you in a CSS file specify a background color for you BODY element like this:

    body {
    background: black;
    }

    Then this color is respected when the page is rendered in IE8 if you include a jQuery with a version lower than 1.6.1. If you include 1.6.1 the backgound color is set to white.

    I have tested this with the smallest possible HTML file and 1.5.2, 1.6 and 1.6.1. It works for 1.5.2 and 1.6, but it breaks in 1.6.1.

    Please fix this.

  9. @Larry:
    I can’t recreate the issue. mind making a forum post? these comments aren’t meant for support/bug requests.

  10. Hi,

    I switched from 1.5.2 to 1.6.1 and all my events stop work out, I can not use bond or live the way that I can use is $ (element). click (func)

    Perhaps you should stop releasing new versions every other day and maybe start testing jquery before you put it out, it has recently been a lot of bugs.
    It is sad when you always have to go back to the old just because it does not work

    Tightening now guys!

  11. @Nisse:

    No offense, but your comment is very rude.

    First, you should browse the API and learn the differences between binding an event vs. live events.

    Second, you should look into just how much testing goes into jquery

    Third, you should tighten up your own code before you tell the jquery team to do the same.

    Sorry, not trying to flame here but for all this team has done that is a very poor way of expressing frustration over ignorance.

  12. attr on said:

    $(“.test”).val() is “”
    $(“.test”).attr(“value”) is undefined
    $(“.test”).prop(“value”) is undefined
    but if

    everything is fine
    how to get “value” at div?

  13. nata on said:

    @attr

    To get value for div, you can make use on

    $(“#div1”).html() or $(“#div1”).text()

  14. nata on said:

    Thank you for the fixed done in ver 1.6.1. Specially continue supported for backward compability issue on attr(“”) and make clear on prop(“”) usage.

  15. fred on said:

    I have the same problem as “attr”

    if you have the div: bar

    @1.5.2 you can get the attribute “value” with $(‘.test’).attr(‘value’)
    @1.6.1 you can’t get the attribute “value”

  16. Oliver on said:

    I understand the problem, but not this solution. Why didn’t you add a function initial or something like this to set the initial attribute of an object (just a few people need this) and merge prop with attr and to keep it backwards compatible?

  17. I really thank the jQuery team for the job on 1.6.1

    I was trying these days do manipulate a checkbox an encountered some problems.

    If I check a box using:
    $(“input[name=’ppbras'”]).attr(“checked”,true);
    or
    $(“input[name=’ppbras'”]).attr(“checked”,”checked”);

    It works fine at the first time. But when the user click again and “uncheck” the box, and I run the script again, it does not work.
    I really didn’t discover why.

    My way to fix it was:
    $(“input[name=’ppbras'”])(0).checked = true;

    And this way, works perfectly!

  18. Gracias por el gran esfuerzo que hacen por llevar adelante este grandioso proyecto. Saludos desde Paraguay

  19. There is something strange when sending an empty array in a Ajax call, like

    $.post(“/whatever”, {foo: [1,2,3], bar: []}, function(data) {…});

    Using jQuery 1.5.2 the “bar” parameter gets in the server (Rails) as an empty array, but using 1.6.1 it does
    not appear in the request parameters at all.

  20. attr on said:

    sorry post again

    <div class="test" value="1" <</div<
    $(“.test”).val() is “”
    $(“.test”).attr(“value”) is undefined
    $(“.test”).prop(“value”) is undefined
    but if
    <input class=".test" value="1" <</input<
    or rename "value" to "anything"
    everything is fine

    how to get “value” at div?

  21. reanimax on said:

    1.6.1 IS NOT BACKWARD COMPATIBLE with 1.5.2, i tested it on my website where and it stopped working as it should even though no javascript error occurs

    since you provide no migration instruction, i have to stay behind with 1.5.X

  22. Jay River on said:

    I don’t mean to be rude in any way, but I have to agree with some of the comments posted here about the very obvious decline of quality in the latest versions of jQuery. When I first started using jQuery it actually did HELP me to resolve cross-browser issues and it made my life easier. As of 1.5+, jQuery has just started to CREATE problems for me instead and it appears to me you lack proper methods for regression testing.

    I experience the same problems as Larry above regarding CSS. Another problem which really makes me start thinking about leaving jQuery altogether is the appereance of infinite loops which I never had in versions prior 1.5. At situations that do no appear to be reproduceable, jQuery goes into infinite loops on Firefox in ways that really mess up the user experience. Google on this subject and you will see the frustration many others clearly experience.

    I really do suggest you jQuery guys take a minute to ponder in which way you have been doing things lately and that you slow down this version drive you have started lately. Clearly along the way you have lost track of the importance of quality instead of quantity (having in mind the amount of releases you have created just in the past year!).

  23. i have a question…
    is it SO SO HARD for you to make it easey to download?
    are you so Superb that you assume we want to see every fucking thing you write?
    if im looking for a damn fucking .ZIP FILE, why are you making it so so so SOOOO hard to find? is it like ur brains that are invisible files?

  24. damian_sux on said:

    Eat shit damian.

    If you are using jQuery as a developer you should know that you can either link it in your header or right click, save as to save the .js file to your hard drive and/or server.

    Apparently you can’t figure out either of those so you don’t belong here.

  25. Michael Lane on said:

    I have CS4 Dreamweaver with jqery-1.2.6. Is there a way I can replace the older version with this new version so that when I insert a gadget that uses the older version, it links and includes the newer version automatically?

    I can do is manually, but I would like it to be automated in Dreamweaver CS4 if possible.

  26. njam on said:

    /attr\s*\(\s*[‘”]\s*(async|autofocus|checkedlocation|multiple|readOnly|selected)/

  27. reanimax on said:

    i have issues with events, “Nisse” also posted some stuff about events problems, somebody should nuke this realease

  28. maofree on said:

    Hi
    many plugins for jquery like nivo slider, popeye, tipTip, …… don’t work with the last 1.6.1 (for 1.6 is the same)

  29. jason on said:

    hi,
    There are many Jquery PlugIns haven’t compatibale with jquery1.6.1.. so privous version a good choice for developers~