You are on page 1of 1

test

CHAPTER 4
jQuery Utilities
Jonathan Sharp
4.0 Introduction
Often, when thinking and talking about jQuery, the main concepts that come to mind
are DOM and style manipulation and behavior (events). Yet there are also a number
of core features and utility functions tucked away for the developers benefit. This
chapter is focused on exposing, disclosing, and explaining these not-so-common utility
methods of jQuery.
4.1 Detecting Features with jQuery.support
Problem
You need to attach a special click handler to all anchor tags that have just a hash for
the current page, and you dont want to risk it breaking because of browser support
issues.
Solution
(function($) {
$(document).ready(function() {
$('a')
.filter(function() {
var href = $(this).attr('href');
// Normalize the URL
if ( !jQuery.support.hrefNormalized ) {
var loc = window.location;
href = href.replace( loc.protocol + '//' + loc.host + loc.pathname,
'');
}
// This anchor tag is of the form <a href="#hash">
return ( href.substr(0, 1) == '#' );
})
77

You might also like