[class^=page-calendar-practices]
will only select an element who's class attribute starts with "page-calendar-practices"; not an element of which one of its classes starts with "page-calendar-practices".
So it would select an element such as this:
<body class="page-calendar-practices-2012-05">
You can use the *
selector:
$('body[class*=page-calendar-practices]')
but that will also select the following:
<body class="page some-page-calendar-practices">
Alternatively, you can filter with this simple check:
$('body').filter(function() {
return ~(' ' + this.className).indexOf(' page-calendar-practices');
}).find('#content-header h1#title');
which is a little more verbose than the simple "contains" selector, but is more accurate.
Here's the fiddle: http://jsfiddle.net/DR9K4/
To make things easier, you can add your own filter to jQuery, as follows:
jQuery.expr[':']['class-starts'] = function(el, i, m) {
return ~(' ' + el.className).indexOf(' ' + m[3]);
};
and then simply use it wherever you want:
$('body:class-starts(page-calendar-practices)');
See it here in action: http://jsfiddle.net/gEJeW/
Update: In jQuery 1.8, the Sizzle engine was completely rewritten. As part of the update, the expression extension architecture has also been reworked, so the above function won't work anymore.
If you're using jQuery 1.8+, use this:
$.expr[':']['class-starts'] = $.expr.createPseudo(function (arg) {
return function (el) {
return ~(' ' + el.className).indexOf(' ' + arg);
};
});
Here's the fiddle: http://jsfiddle.net/gEJeW/2/
For more information, see here: Getting the "match" object in a Custom Filter Selector in jQuery 1.8