Example 4.3. Storing a relationship between elements using $.fn.data
$('#myList li').each(function() { var $li = $(this), $div = $li.find('div.content'); $li.data('contentDiv', $div); }); // later, we don't have to find the div again; // we can just read it from the list item's data var $firstLi = $('#myList li:first'); $firstLi.data('contentDiv').html('new content');
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.
Example 4.4. Putting jQuery into no-conflict mode
<script src="prototype.js"></script> <script src="jquery.js"></script> <script>var $j = jQuery.noConflict();</script>
Example 4.5. Using the $ inside a self-executing anonymous function
<script src="prototype.js"></script> <script src="jquery.js"></script> <script> jQuery.noConflict(); (function($) { // your code here, using the $ })(jQuery); </script>
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.