Skip to content

Instantly share code, notes, and snippets.

@johntimothybailey
Created April 29, 2012 21:21
Show Gist options
  • Save johntimothybailey/2553326 to your computer and use it in GitHub Desktop.
Save johntimothybailey/2553326 to your computer and use it in GitHub Desktop.
Polyfills for jQuery to work in IE5.5

This is intended as crude workarounds for filling jQuery specifically in IE 5.5. Note, this is not intended to be a comprehensive solution nor is it aimed at supporting both legacy browsers and modern browsers.

jQuery.fn.append = function( ) {
var element = this.get(0);
var appending = arguments[0];
if( appending.charAt(0) === "<" ){
throw Error("This appears to be a dom element represented as a string. Please create the element then append");
} else{
// Wonder if there is a better way to do this
element.innerHTML = element.innerHTML + appending;
}
};
jQuery.fn.isString = function ( value ){
return typeof value === "string";
}
// I would rather like to know why jQuery.access fails silently in IE 5.5. In the meantime, this resolves the issues of accessing attributes.
jQuery.fn._attr = jQuery.fn.attr;
jQuery.fn.attr = function ( ) {
var key = arguments[0];
if(arguments.length == 1) { // Perform a get
this.get(0).getAttribute(key);
}else{
this.get(0).setAttribute(key,arguments[1]);
}
}
jQuery.fn.prepend = function( ) {
var element = this.get(0);
var appending = arguments[0];
if(typeof appending === "string"){
if( appending.charAt(0) === "<" ){
throw Error("This appears to be a dom element represented as a string. Please create the element then prepend");
} else{
// Wonder if there is a better way to do this
element.innerHTML = appending + element.innerHTML;
}
}else{
element.insertBefore(arguments[0]);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment