0

Hi guys, please tell me how to add the method wrapper.getHtml() to the beginning of the body before script. document.write adds

class HtmlElement { TagName = ''; isTagSelfClose = false; text = ''; arrAttributies = []; arrStyles = []; arrTag = []; constructor(tagName, isTagSelfClose, text = undefined) { this.tagName = tagName; this.isTagSelfClose = isTagSelfClose; this.text = text; this.arrAttributies = []; this.arrStyles = []; this.arrTag = []; } setAttributies(value) { this.arrAttributies.push(value); } setStyle(value) { this.arrStyles.push(value); } setTagInEnd(value) { this.arrTag.push(value); } setTagInBegin(value) { this.arrTag.unshift(value); } getStringTags() { let stringTags = ""; for (let i = 0; i < this.arrTag.length; ++i) { stringTags += `${this.arrTag[i].getHtml()}`; if (i != this.arrTag.length - 1) { stringTags += "\n"; } } return stringTags; } getStringAttributies() { let stringAttributies = ""; for (let i = 0; i < this.arrAttributies.length; ++i) { stringAttributies += `${this.arrAttributies[i].name}=${this.arrAttributies[i].value}`; if (i != this.arrAttributies.length - 1) { stringAttributies += " "; } } return stringAttributies; } getStringStyles() { let stringStyles = `style=`; for (let i = 0; i < this.arrStyles.length; ++i) { stringStyles += this.arrStyles[i].name + ':' + this.arrStyles[i].value + ";"; } return stringStyles; } getHtml() { if (this.isTagSelfClose) { return (`<${this.tagName} ${(this.arrAttributies.length > 0) ? this.getStringAttributies() : +''} ${(this.arrStyles.length > 0) ? this.getStringStyles() : +''}/>`); } else { return (`<${this.tagName} ${(this.arrAttributies.length>0)?this.getStringAttribu

23rd May 2021, 9:11 PM
Тимур Завьялов
Тимур Завьялов - avatar
2 Respuestas
0
getHtml() { if (this.isTagSelfClose) { return (`<${this.tagName} ${(this.arrAttributies.length > 0) ? this.getStringAttributies() : +''} ${(this.arrStyles.length > 0) ? this.getStringStyles() : +''}/>`); } else { return (`<${this.tagName} ${(this.arrAttributies.length>0)?this.getStringAttributies():+''} ${(this.arrStyles.length>0) ? this.getStringStyles() :+''}>${(this.text == undefined)?"":this.text} ${(this.arrTag.length > 0)?this.getStringTags():''}</${this.tagName}>`); } } } let wrapper = new HtmlElement("div", false); wrapper.setStyle({ name: "display", value: "flex" }); wrapper.setAttributies({ name: "id", value: "wrapper" }) let div = new HtmlElement("div", false); div.setStyle({ name: "width", value: "300px" }); div.setStyle({ name: "margin", value: "10px" }); let h3 = new HtmlElement("h3",false," What is Lorem Ipsum ?"); let img = new HtmlElement("img",true); img.setStyle({ name: "width", value: "100%" }); img.setAttributies({ name: "src", value: "https://image.shutterstock.com/image-vector/white-jpg-file-document-download-260nw-1500246968.jpg" }); img.setAttributies({ name: "alt", value: "Lorem Ipsum" }); div.setTagInBegin(h3); div.setTagInEnd(img); let p = new HtmlElement("p",false,`Lorem Ipsum is simply dummy text of the printing and typesetting industry . Lorem Ipsum has been the industry's standart dummy text ever since the 1500s.`); let a = new HtmlElement("a",false,"More..."); a.setAttributies({ name:"href", value: "https://www.lipsum.com/" }); a.setAttributies({ name:"target", value:"_blank" }); p.setStyle({ name:"text-align", value:"justify" }); p.setTagInBegin(a); div.setTagInEnd(p); wrapper.setTagInBegin(div); wrapper.setTagInEnd(div); // document.write(wrapper.getHtml()); let n = document.querySelector('body') n.insertAdjacentElement('afterbegin', wrapper.getHtml())
23rd May 2021, 9:13 PM
Тимур Завьялов
Тимур Завьялов - avatar
0
Hi I am the absolute bigger what 8s your advice for me?
23rd May 2021, 9:14 PM
Dn Fisehatsion Adisu
Dn Fisehatsion Adisu - avatar