Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging multiple div background onclick , onmouseout and onmouseover
    primarykey
    data
    text
    <p>I'm working in a project here for over 30 hours and I might not be thinking straight. </p> <p>Here's my situation. I have basically 4 divs that changes they background in diferents ways depending on the mouse action. </p> <p>Lets call those divs here as div_1, div_2, div_3 and div_4.</p> <p>When the user pass the mouse over the bottons on the menu the div_1 and div_2 should change they background to the background related to the button.</p> <p>When the user click on a botton all the 4 divs should change they background and keep it even if the user move the mouse elsewhere. </p> <p>And the last situation that you need to imagine is the one where the user clicked on one botton and after he pass the mouse over another botton. On this case, the div_1 and div_2 will still change but if the user remove the mouse from the menu div_1 and div_2 should return to the background related to the same background as div_3 and div_4.</p> <p>I would appreciate if someone could help me to realize whats wrong with my code. Tnx. </p> <p>Here is my code:</p> <pre><code> &lt;ul&gt; &lt;li id="menu-a1" onclick="Menu('a1','click');" onmouseover="('a1','over');" onmouseout="Menu('a1','out');" &gt; &lt;a href="#"&gt;Menu_a1&lt;/a&gt; &lt;/li&gt; &lt;li id="menu-a2" onclick="Menu('a2','click');" onmouseover="('a2','over');" onmouseout="Menu('a2','out');" &gt; &lt;a href="#"&gt;Menu_a2&lt;/&lt;/a&gt; &lt;/li&gt; &lt;li id="menu-a3" onclick="Menu('a3','click');" onmouseover="('a3','over');" onmouseout="Menu('a3','out');" &gt; &lt;a href="#"&gt;Menu_a3&lt;/&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;div id=div_1&gt;&lt;/div&gt; &lt;div id=div_2&gt;&lt;/div&gt; &lt;div id=div_3&gt;&lt;/div&gt; &lt;div id=div_4&gt;&lt;/div&gt; </code></pre> <p>heres my java script:</p> <pre><code>function Menu(where, action) { switch (action) { case 'click': if ($('#menu-'+where).hasClass('active')) { ClearMenu(); $('#menu-'+where).removeClass('active'); } else { $('#menu-'+where).addClass('active'); ClearMenu(); ActiveMenu(where); } break; case 'over': ActiveMenu(where); OverMenu(where); break; case 'out': ActiveMenu(where); break; default: break; } } function ClearMenu(){ // Removing Classes $('#div_1').removeClass('a1 a2 a3'); $('#div_2').removeClass('a1 a2 a3'); $('#div_3').removeClass('a1 a2 a3'); $('#div_4').removeClass('a1 a2 a3'); function OverMenu(where){ $('#div_1').addClass(where); $('#div_2').addClass(where); } function ActiveMenu(where){ // Adding Classes $('#div_1').addClass(where); $('#div_2').addClass(where); $('#div_3').addClass(where); $('#div_4').addClass(where); } </code></pre> <p>and here is my css:</p> <pre><code>#div_1.a1 {background:url(background_div1_a1.jpg)} #div_1.a2 {background:url(background_div1_a2.jpg)} #div_1.a3 {background:url(background_div1_a3.jpg)} #div_2.a1 {background:url(background_div2_a1.jpg)} #div_2.a2 {background:url(background_div2_a2.jpg)} #div_2.a3 {background:url(background_div2_a3.jpg)} #div_3.a1 {background:url(background_div3_a1.jpg)} #div_3.a2 {background:url(background_div3_a2.jpg)} #div_3.a3 {background:url(background_div3_a3.jpg)} #div_4.a1 {background:url(background_div4_a1.jpg)} #div_4.a2 {background:url(background_div4_a2.jpg)} #div_4.a3 {background:url(background_div4_a3.jpg)} </code></pre>
    singulars
    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.
 

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