Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to update background-color of nested div in group of divs
    primarykey
    data
    text
    <p>I've hit a road block and I'm not sure where to look.</p> <p>I have a single div that is 200px by 200px. Within that I have 4 other divs that are 65px by 65px and they are positioned absolute and aligned to all 4 corners of the outer div. I have created a function that when a user clicks on one of the inner divs, that div color is updated and the 3 other divs background-colors are reset. Currently, if I click either of the top 2 divs it works. If I click either of the bottom 2 divs, it doesn't work.</p> <p>I have a feeling it has something to do with z-index and maybe block alignment, but that is just a guess now.</p> <p>I've added my code below.</p> <p><strong>HTML:</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="scripts1.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(){ BuildHandler(); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="mini_container"&gt; &lt;div id="top_left" class="mini_boxes"&gt;&lt;/div&gt; &lt;div id="top_right" class="mini_boxes"&gt;&lt;/div&gt; &lt;div id="low_left" class="mini_boxes"&gt;&lt;/div&gt; &lt;div id="low_right" class="mini_boxes"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>scripts1.js</strong></p> <pre><code>function BoxClicked(event){ var targetBoxID = event.target.id; switch (targetBoxID) { case "top_left": $("#top_left").css("background-color","#0099FF"); $("#top_right").css("background-color","#99CCFF"); $("#low_left").css("background-color","#99CCFF"); $("#low_right").css("background-color","#99CCFF"); break; case "top_right": $("#top_left").css("background-color","#99CCFF"); $("#top_right").css("background-color","#0099FF"); $("#low_left").css("background-color","#99CCFF"); $("#low_right").css("background-color","#99CCFF"); case "low_left": $("#top_left").css("background-color","#99CCFF"); $("#top_right").css("background-color","#99CCFF"); $("#low_left").css("background-color","#0099FF"); $("#low_right").css("background-color","#99CCFF"); case "low_right": $("#top_left").css("background-color","#99CCFF"); $("#top_right").css("background-color","#99CCFF"); $("#low_left").css("background-color","#99CCFF"); $("#low_right").css("background-color","#0099FF"); } } function BuildHandler(){ var theBoxes = document.getElementsByClassName("mini_boxes"); for(i=0;i&lt;theBoxes.length;i++){ theBoxes[i].addEventListener('click', BoxClicked, false); } } </code></pre> <p><strong>style1.css</strong></p> <pre><code>#mini_container{ width:200px; height:200px; background-color:#C4CFCE; position:relative; z-index:100; } .mini_boxes{ width:65px; height:65px; background-color:#99CCFF; z-index:200; } #top_left{ position:absolute; top:0px; left:0px; } #top_right{ position:absolute; top:0px; right:0px; } #low_left{ position:absolute; bottom:0px; left:0px; } #low_right{ position:absolute; bottom:0px; right:0px; } </code></pre> <p>Any pointers would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload