Jump to content

koorosh13hm

Members
  • Posts

    6
  • Joined

  • Last visited

Posts posted by koorosh13hm

  1. Hi everyone,

    I have tried to assign an event to a member inside an object by using an anonymous function.

    In the code below the result would not be gained and I even see no errors in the console.

    Could you please help me fix this issue?

    Thank you very much in advance.

    <!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title>2js</title>    <style type="text/css">        div.box {            background-color: hsl(0, 0%, 0%);            margin-left: 2px;            width: 2px;            height: 2px;            margin-top: 2px;            display: block;            border-radius: 0.5px;            float: left;        }        div.wrapper {            width: 1000px;            height: 800px;            margin: 0 auto;            background-color: #000000;        }    </style></head><body><div class="wrapper"> </div><script type="text/javascript">    window.onload = function init(){        var wrappers = document.getElementsByClassName("wrapper")[0];        for (var i=0; i<=49999; i++){            var newDiv = document.createElement("div");            newDiv.id = "box" + i;            newDiv.className = "box";            wrappers.appendChild(newDiv);        }        var boxs = document.getElementsByClassName("box");        console.log("boxs length is: " + boxs.length);        //here is to check the type of boxs        if (Array.isArray(boxs)){            console.log("boxs is of type Array.");        }else{            console.log("boxs is of type: " + typeof boxs);    //object is returned        }        for (var item in boxs){            if (boxs.hasOwnProperty(item)){                console.log(item + "->" + boxs[item]);  //the result would be like: box49999->[object HTMLDivElement]            }            item.onmousemove = function (){           //Here is where I supposed would return the result                item.style.backgroundColor = "green";                console.log("ever done?");           //it results nothing!!            }        };} //end of script tag</script></body></html>
  2. Actually I have tried this line of command too:

     

    var wrappers = document.getElementsByClassName("wrapper")[0];

     

    and have removed document as told, But there is no trace of any new div shown!!!!!

    In the chrome Inspect Element section yhe width and height of the div.box is shown as 0.

  3. Actually I have tried this line of command too:

     

    var wrappers = document.getElementsByClassName("wrapper")[0];

     

    and have removed document as told, But there is no trace of any new div shown!!!!!

  4. Hi everyone,

    I have been trying to fix this issue by visiting the forums here and there

    and also tried to do exactly what I learned from them yet, I am unable

    to add a div to another one. The error message in the console is :

     

    Uncaught TypeError: Cannot read property 'appendChild' of undefined

     

    And the code that I have been using is as follows. Could you please help me with this issue?

     

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title>1js</title>
    <style type="text/css">
    div.box {
    background-color: hsl(0, 0%, 0%);
    margin-left: 15px;
    width: 20px;
    height: 20px;
    }
    div.wrapper {
    width: 400px;
    height: 200px;
    background-color: green;
    margin: 0 auto;
    }
    </style>
    </head>
    <body>
    <div class="wrapper"> </div>
    <script type="text/javascript">
    var wrappers = document.getElementsByClassName("wrapper");
    var newDiv = document.createElement("div.box");
    document.wrappers.appendChild(newDiv);
    }
    </script>
    </body>
    </html>
×
×
  • Create New...