Elem.js 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. export default class Elem {
  2. constructor(elem){
  3. this.elem = document.createElement(elem);
  4. }
  5. id(v){
  6. this.elem.id = v;
  7. return this;
  8. }
  9. addClass(v){
  10. this.elem.classList.add(v);
  11. return this;
  12. }
  13. text(v){
  14. this.elem.textContent = v;
  15. return this;
  16. }
  17. type(v){
  18. this.elem.type = v;
  19. return this;
  20. }
  21. placeholder(v){
  22. this.elem.placeholder = v;
  23. return this;
  24. }
  25. onsubmit(v){
  26. this.elem.onsubmit = v;
  27. return this;
  28. }
  29. append(v){
  30. if(v instanceof this.constructor){
  31. this.elem.appendChild(v.elem);
  32. }else{
  33. this.elem.appendChild(v);
  34. }
  35. return this;
  36. }
  37. appendTo(v){
  38. if(v instanceof this.constructor){
  39. v.elem.appendChild(this.elem);
  40. }else{
  41. v.appendChild(this.elem);
  42. }
  43. return this;
  44. }
  45. get(){
  46. return this.elem;
  47. }
  48. }