Updating JQuery 1.4+ (or older) to 1.7+ (“attr” replacement)

We were trying to update the Jquery from 1.4 to 1.7 to get new functions in and also to get better working with JQuery UI and with jqGrid.

Suddenly we hit a ROAD BLOCK! the Jquery decided to change the behaviour of method to soemthign different. We used attr function extensively in our app, so replacing it in 3000 location and than verifying it would mean lot of typos and QA effort. They changed it to prop !

So we just simply wrote and override to attr! and extended jQuery…

jQuery.fn.attr = function(a, b) {
if (a == null && a == undefined
&& b == null && b == undefined) {
return ;
if (a != null && b != null)
return $(this).prop(a, b);
if (a != null && (b == null || typeof (b) == “undefined”))
return $(this).prop(a);

copy this into your code and enjoy beauty of it…