For example, we may want to establish a relationship between a list item and a div that's inside of it. We could establish this relationship every single time we interact with the list item, but a better solution would be to establish the relationship once, and then store a pointer to the div on the list item using $.fn.data
:
Although jQuery eliminates most JavaScript browser quirks, there are still occasions when your code needs to know about the browser environment.
jQuery offers the $.support
object, as well as the deprecated $.browser
object, for this purpose. For complete documentation on these objects, visit http://api.jquery.com/jQuery.support/ andhttp://api.jquery.com/jQuery.browser/.
The $.support
object is dedicated to determining what features a browser supports; it is recommended as a more “future-proof” method of customizing your JavaScript for different browser environments.
If you are using another JavaScript library that uses the $
variable, you can run into conflicts with jQuery. In order to avoid these conflicts, you need to put jQuery in no-conflict mode immediately after it is loaded onto the page and before you attempt to use jQuery in your page.
When you put jQuery into no-conflict mode, you have the option of assigning a variable name to replace $
.
You can continue to use the standard $
by wrapping your code in a self-executing anonymous function; this is a standard pattern for plugin authoring, where the author cannot know whether another library will have taken over the $
.
The $.browser
object was deprecated in favor of the $.support
object, but it will not be removed from jQuery anytime soon. It provides direct detection of the browser brand and version.
jQuery offers the $.support
object, as well as the deprecated $.browser
object, for this purpose. For complete documentation on these objects, visit http://api.jquery.com/jQuery.support/ andhttp://api.jquery.com/jQuery.browser/.
The $.support
object is dedicated to determining what features a browser supports; it is recommended as a more “future-proof” method of customizing your JavaScript for different browser environments.
The $.browser
object was deprecated in favor of the $.support
object, but it will not be removed from jQuery anytime soon. It provides direct detection of the browser brand and version.