Created
June 10, 2013 00:33
-
-
Save davidwkeith/5745871 to your computer and use it in GitHub Desktop.
Example of document.createElement enhancement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any future updates will be at https://gitlab.com/snippets/29013