Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. function e(type, opts) {
  2. var i;
  3. if (!opts) opts = {};
  4. i = type.indexOf(".");
  5. if (i >= 0) { opts.className = type.slice(i+1); type = type.slice(0, i); }
  6. i = type.indexOf("#");
  7. if (i >= 0) { opts.id = type.slice(i+1); type = type.slice(0, i); }
  8. var d = document.createElement(type||"div");
  9. if (opts.className) d.className = opts.className;
  10. if (opts.id) d.id = opts.id;
  11. if (opts.parent) opts.parent.appendChild(d);
  12. Object.keys(opts).forEach(function(k){
  13. if (k !== "parent" && k !== "className" && k !== "id") {
  14. if (k.slice(0, 2) == "s_") {
  15. d.style[k.slice(2)] = opts[k];
  16. } else {
  17. d[k] = opts[k];
  18. }
  19. }
  20. });
  21. Array.prototype.slice.call(arguments, 2).forEach(function(c) {
  22. if (typeof c === "string") {
  23. d.appendChild(document.createTextNode(c))
  24. } else {
  25. d.appendChild(c);
  26. }
  27. });
  28. return d;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement