Skip to content

Instantly share code, notes, and snippets.

@roykolak
Created January 28, 2009 22:40
Show Gist options
  • Save roykolak/54229 to your computer and use it in GitHub Desktop.
Save roykolak/54229 to your computer and use it in GitHub Desktop.
Pseudo class (for IE6)
function PseudoClass(autotarget) {
this.targets = [];
if((autotarget != undefined) && (autotarget == true)) {
this.attach(true);
}
}
PseudoClass.prototype.addTarget = function(target) {
this.targets.push(target);
return target;
}
PseudoClass.prototype.attach = function(autotarget) {
var self = this;
if((autotarget != undefined) && (autotarget == true)) {
$('.js_pseudo_class').each(function(index, element) {
self.byTarget(element);
});
}
jQuery.each(self.targets, function(index, target) {
self.byTarget(target);
});
self.targets = null;
}
PseudoClass.prototype.byTarget = function(target) {
var children = $(target).children();
if(children.length > 1) {
$(children.get(0)).addClass('first-child');
$(children.get(children.length - 1)).addClass('last-child');
} else if(children.length == 1) {
$(children.get(0)).addClass('only-child');
}
}
// Attach fake Pseudo Classes for IE6. It is done outside of head for speed reasons
if($.browser.msie && ($.browser.version.match(/^6/) != -1)) {
new PseudoClass(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment