Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
- <html>
- <head>
- <title>DOM Example</title>
- <script type="text/javascript" language="javascript">
- function DivObject(id, text)
- {
- this.id = id;
- this.text = text;
- }
- DivObject.prototype.createDiv = function() {
- d = document.createElement("div");
- d.id = this.id;
- var tn = document.createTextNode(this.text);
- d.appendChild(tn);
- return d;
- };
- DivObject.prototype.addtoDocument = function() {
- var dv = document.getElementsByTagName('div');
- document.body.insertBefore(d,dv);
- //var dv=document.getElementsByTagName("div");
- //document.body.insertBefore(Div.createDiv(), dv);
- }
- var c = new DivObject("div2", "This is a div");
- c.createDiv();
- </script>
- </head>
- <body>
- <h1>Hello Class</h1>
- <div="div1">asdfadsf
- </div>
- <p align="center">
- <b>Click this button to create div element dynamically:</b>
- <input id="btn1" type="button" value="create div" onclick="c.addtoDocument();" />
- </p>
- </body>
- </html>
- <!--
- function Cook(recipe, ingredient1, tool)
- {
- this.recipe = recipe;
- this.ingredient1 = ingredient1;
- this.tool = tool;
- }
- Cook.prototype.stir = function() {
- return "Stir with the " + this.tool;
- };
- Cook.prototype.add = function() {
- return "Add "+this.ingredient1+" to the pot."
- };
- function Div(id, text, place)
- {
- this.id = id;
- this.text = text;
- this.place = place;
- }
- Div.prototype.createDiv = function() {
- var d = document.createElement("div");
- d.id = this.id;
- return d;
- };
- Div.prototpe.addDocument = function()
- {
- insertBefore(Div.createDiv(), document.body.children[this.place]);
- }
- String.prototype.rot13 = function(){var a = "a".charCodeAt(0);
- var z= "z".charCodeAt(0);
- s = this.toLowerCase();
- var r = "";
- for(var i=0;i<s.length;i++)
- {
- var c=s.charCodeAt(i);
- if(c<a||c>z)
- {
- r+=s.charAt(i);
- continue;
- }
- c-=a;
- var rc=((c+13)%26);
- rc+=a;
- r+=String.fromCharCode(rc);
- }
- return r;
- }*/ -->
Add Comment
Please, Sign In to add comment