html - How do I get my color palette to display using javascript? -
html - How do I get my color palette to display using javascript? -
i beginner in web dev , have color palette homework need do. followed instructions problem my color palette not show @ in browser. there instruction misinterpreting?
html code:
<!doctype html> <html lang='en'> <head> <meta charset='utf-8' /> <title>javascript fun</title> <style type='text/css'> .palette { float: left; height: 50px; width: 100px; } </style> <script type='text/javascript'> </script> </head> <body> <div id='palette-div' style='border:2px solid white; float:left;'> </div> <div id='color-div' style='clear:both; position:relative; left:0;'> </div> <script type='text/javascript'> //<![cdata[ //<!-- // 1. define array indexes @ to the lowest degree 8 colors. var colors = ["#7fff00", "#8b008b", "#e9967a", "#00bfff", "#daa520", "#cd5c5c"]; var palette = ""; // 2. iterate through colors array, concatenating string div class 'palette // variable - palette. // 3. add together inline style each div background color of div corresponds // current index of colors array. // 4. add together event listener each div setbgcolor() called when // div clicked. for(var = 0; < colors.length; i++) { palette = palette + " <div class='palette'" + " style='background-color:" + + "' onclick='setbgcolor()'> </div>"; } // 5. add together palette variable contents of 'palette-div' div. document.getelementbyid('palette-div').innerhtml = palette; function setbgcolor( clickeddiv ) { // 6. create variable that's equal background color of clickeddiv var currentcolor = clickeddiv.style.backgroundcolor; // 7. set contents of 'color-div' equal variable in (6). // (the rgb value should displayed in 'color-div', not color itself). document.getelementbyid('color-div').innerhtml = currentcolor; // 8. set background color of entire page background color of clickeddiv. document.body.style.backgroundcolor = currentcolor; // 9. now, fun, move 'color-div' 10px right, every time // colored div clicked. document.getelementbyid('color-div').style.left = '10px'; } //--> //]]> </script>
javascript html
Comments
Post a Comment