jquery extend
June 16th, 2008 Filed Under Good to know, Javascript, Tips & Tricks, browser, gyan, jQuery, snippet
I have learnt the way to extend any jquery object today. I’ll show an example of adding an extra browser check to the browser object.
jquery has browser object as $.browser. So when you query this object you get mozilla, msie, opera, safari and version as the members of this object. Now if you want to add another browser say aol to the object you need to extend it like this:
$.extend($.browser, {aol: /AOL/.test(navigator.userAgent)});
The extend object does the job pretty neatly for you. The first parameter that goes is the object to be extended and the second parameter is the prop object which goes and sits in the extendee object.
So, to query you need to invoke is:
$.browser.aol // returns boolean
That’s great to know for the guys new to jquery. Enjoy madi !!!
Post Linx
Permalink | Trackback |
|
Print This Article |
Comments
Leave a Reply

