-
-
Save jed/993452 to your computer and use it in GitHub Desktop.
write html/text to any node
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
function( | |
a, // dom node: only document, element, text, comment, or attribute supported | |
b, // text or html to write | |
c | |
){ | |
c = a.nodeType; // get the node type | |
c > 8 // if it's the document | |
? a.close( // close the document after | |
a.open(), // opening it and | |
a.write(b) // writing the html, | |
) | |
: a[ // otherwise, on the node | |
[ // get the appropriate property, | |
, // (elided placeholder for 0) | |
"innerHTML", // "innerHTML" for nodeType==1 (elements), | |
"value" // "value" for nodeType==2 (attributes), | |
][c] // based on the nodeType, | |
|| "nodeValue" // or use "nodeValue" (comments and text nodes), | |
] = b // and set the text or html. | |
} |
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
function(a,b,c){c=a.nodeType;c>8?a.close(a.open(),a.write(b)):a[[,"innerHTML","value"][c]||"nodeValue"]=b} |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
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
{ | |
"name": "write", | |
"description": "write html/text to any node", | |
"keywords": [ | |
"innerHTML", | |
"write", | |
"attribute", | |
"DOM" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider adding:
to support setting the value of an input element?