Jump to content

creating elements with OOP


Recommended Posts


<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>title</title><style>.lol {    border:1px solid black}</style><script>window.onerror = function(m, u, l){alert('Javascript Error: '+m+'nURL: '+u+'nLine Number: '+l);return true;}</script><script>window.onload = init;function init() {document.getElementById('btn1').onclick = test;}function little(x) {    this.element =x;    var matej=this.element.getAttribute("data-size");    if(matej!==null){    this.element.style.width = matej + "px";    this.element.style.height = matej + "px";    }}little.prototype.color = function() {  this.element.style.backgroundColor="red";};function test(){var kek=document.getElementsByClassName("lol");var g=[];for(var i=0;i<kek.length;i++){    var l = new little(kek[i]);    l.color();    g.push(l);}}//end text</script></head><body><input type="button" id="btn1" value="Enter"><div  class="lol" data-size="100"></div><div  class="lol" data-size="110"></div><div  class="lol" data-size="120"></div><div  class="lol" data-size="130"></div></body>    </html>

Looking at the subject line, I don't see any elements being created. I see an array of objects being created.

Link to comment
Share on other sites

Thank you .


Yea sorry , im not good at naming thins or subject :/


anyway , i tried to add a child div to one of them here http://jsfiddle.net/hc4erouc/3/ but whenever i set both



it aint working , but when i add just this


this.element.style.width=parseInt(this.element.parentNode.style.width/2)+"px" // this works strange , it add width of element but instead of 50% of parent's width it adds 100% of parent's widththis.element.style.height=20+"px"
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...