Skip to content

Instantly share code, notes, and snippets.

@davidwkeith
Created June 10, 2013 00:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwkeith/5745871 to your computer and use it in GitHub Desktop.
Save davidwkeith/5745871 to your computer and use it in GitHub Desktop.
Example of document.createElement enhancement
// not sure how to detect this yet, stay tuned or leave a comment
window.document._createElement = window.document.createElement;
window.document.createElement = function(name, attributes) {
if (typeOf attributes === 'string') {
// Chrome adds an undefined 'is' attribute for the second arg, why is this?
// Chrome is also throwing a TypeError for any third arg I can think of (number, string, object)
return window.document._createElement(arguments);
} else {
var elm = window.document._createElement(name);
for (key in attributes) {
// FIXME: does not support style, or other nested attributes yet
// Assumes all boolean values are present/not-present
if (typeOf attributes[key] === 'boolean') {
if (attributes[key]) {
elm[key] = key;
}
} else {
elm[key] = attributes[key];
}
}
return elm;
}
}
}
@davidwkeith
Copy link
Author

Any future updates will be at https://gitlab.com/snippets/29013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment