Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Element = (function (tag) {
- this.tag = tag;
- this.object = "";
- this.clas = "";
- this.style = "";
- this.id = "";
- this.content = "";
- this.href = "";
- this.create = function () {
- this.object = document.createElement(this.tag);
- return this;
- };
- this.setContent = function (content) {
- this.content = content;
- this.object.innerHTML = this.content;
- return this;
- };
- this.setId = function (id) {
- this.id = id;
- this.object.setAttribute("id", id);
- return this;
- };
- this.setHref = function (href) {
- this.href = href;
- this.object.setAttribute("href", href);
- return this;
- };
- this.setClass = function (clas) {
- this.clas = clas;
- this.object.setAttribute("class", clas);
- return this;
- };
- this.setStyle = function (style) {
- this.style = style;
- this.object.setAttribute("style", style);
- return this;
- };
- this.appendTo = function (parent) {
- parent.appendChild(this.object);
- return this;
- };
- this.o = function () {
- return this.object;
- };
- this.create();
- return this;
- });
- var container = document.getElementById("divs");
- // start loop here for json data
- var div1 = new Element("div").setClass("span4").setStyle("margin-left: 0.8em;").appendTo(container);
- var div1h2 = new Element("h2").setContent(data["title"]).appendTo(div1.o());
- var div1p = new Element("p").setContent(data["content"]).appendTo(div1.o());
- var div1p2 = new Element("p").appendTo(div1.o());
- var div1p2a = new Element("a").setContent('Read more »').setHref('somurl').setClass("btn").appendTo(div1p2.o());
Advertisement
Add Comment
Please, Sign In to add comment