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…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.