Guest User

Untitled

a guest
Jan 21st, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  2. <html>
  3. <head>
  4. <title>DOM Example</title>
  5.  
  6. <script type="text/javascript" language="javascript">
  7.  
  8. function DivObject(id, text)
  9. {
  10. this.id = id;
  11. this.text = text;
  12. }
  13.  
  14. DivObject.prototype.createDiv = function() {
  15. d = document.createElement("div");
  16. d.id = this.id;
  17. var tn = document.createTextNode(this.text);
  18. d.appendChild(tn);
  19. return d;
  20. };
  21.  
  22. DivObject.prototype.addtoDocument = function() {
  23.  
  24. var dv = document.getElementsByTagName('div');
  25. document.body.insertBefore(d,dv);
  26. //var dv=document.getElementsByTagName("div");
  27. //document.body.insertBefore(Div.createDiv(), dv);
  28. }
  29.  
  30.  
  31. var c = new DivObject("div2", "This is a div");
  32. c.createDiv();
  33.  
  34. </script>
  35. </head>
  36.  
  37. <body>
  38. <h1>Hello Class</h1>
  39. <div="div1">asdfadsf
  40. </div>
  41. <p align="center">
  42. <b>Click this button to create div element dynamically:</b>
  43. <input id="btn1" type="button" value="create div" onclick="c.addtoDocument();" />
  44. </p>
  45.  
  46. </body>
  47. </html>
  48.  
  49.  
  50. <!--
  51. function Cook(recipe, ingredient1, tool)
  52. {
  53. this.recipe = recipe;
  54. this.ingredient1 = ingredient1;
  55. this.tool = tool;
  56. }
  57.  
  58. Cook.prototype.stir = function() {
  59. return "Stir with the " + this.tool;
  60. };
  61.  
  62. Cook.prototype.add = function() {
  63. return "Add "+this.ingredient1+" to the pot."
  64. };
  65.  
  66. function Div(id, text, place)
  67. {
  68. this.id = id;
  69. this.text = text;
  70. this.place = place;
  71. }
  72.  
  73.  
  74. Div.prototype.createDiv = function() {
  75. var d = document.createElement("div");
  76. d.id = this.id;
  77. return d;
  78. };
  79.  
  80. Div.prototpe.addDocument = function()
  81. {
  82. insertBefore(Div.createDiv(), document.body.children[this.place]);
  83. }
  84.  
  85.  
  86. String.prototype.rot13 = function(){var a = "a".charCodeAt(0);
  87.  
  88. var z= "z".charCodeAt(0);
  89.  
  90. s = this.toLowerCase();
  91.  
  92. var r = "";
  93. for(var i=0;i<s.length;i++)
  94. {
  95. var c=s.charCodeAt(i);
  96.  
  97. if(c<a||c>z)
  98. {
  99. r+=s.charAt(i);
  100. continue;
  101. }
  102. c-=a;
  103. var rc=((c+13)%26);
  104.  
  105. rc+=a;
  106.  
  107. r+=String.fromCharCode(rc);
  108. }
  109. return r;
  110. }*/ -->
Add Comment
Please, Sign In to add comment