Update your MVC 3 Projects to JQuery 1.6

A new version of JQuery, the 1.6 was release two days ago, along side with JQuery UI (Combined Library)  1.8.12, jQuery Validation 1.8.0.1 and jQuery Visual Studio 2010 IntelliSense 1.6. If you have started you MVC project with the Tools Update installed then you should have JQuery 1.5.1 integrated in your project. In order to upgrade, in Solution explorer right click your project and select from the menu “Add Library Package Reference…”, on the pop-up select “Updates” and you’ll see all the new NuGet packages there.

After you apply all the updates open you layout files and change the script references like this:

_Layout.cshtml
<head>
<link href="@Url.Content("~/Content/themes/sunny/jquery-ui-1.8.12.custom.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.6.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.12.custom.min.js")" type="text/javascript"></script>

Notice that I am using the Sunny theme that is compatible with JQuery UI  1.8.12 and JQuery 1.6

What’s new

JQuery version 1.6 brings some new methods like prop(), removeProp()holdReady() and improvements to map(), find(), closest() and is().

Be careful when upgrading to 1.6 because there is a big change regarding the differences between html attributes and properties. In JQuery 1.5 you would use $(elem).attr(“checked”) on a checkbox and a Boolean value was returned, in 1.6 attr(“checked”) will return "checked" string, in order to get or set the checked property you should use $(elem).prop("checked").

Another noticeable feature is the new jQuery.map( arrayOrObject, callback( value, indexOrKey ) ) that allows you to traverses objects. The rest of the packages contains bug fixes and small improvements.

Now with NuGet inside Visual Studio, is easy to keep your project up to date and I think that the JQuery library is a main component in web development and  should always be kept to date. Making upgrades that force you to review and change the code are often skipped but if you don’t miss the deadline due to implementing these upgrades you should go for it.

New version: Update fix JQuery 1.6.1