Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery - making hide all/show this div image more generic
    text
    copied!<p>i have the following jquery code. </p> <p>basically i will have several overlapped divs and a list of links on the right of all those overlapped divs. when hovering over a link, the link's assigned div will fade in.</p> <p>I have the following code and it works (it uses the default windows' sample pictures), but if someone can think of a way to optimize it or make it generic, i'd appreciate it.</p> <pre><code>&lt;html&gt; </code></pre> <p> </p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { $("#trigger1").mouseover(function() { $(".contentdiv").addClass("inactive"); $("#divsunset").removeClass("inactive"); $(".inactive").fadeOut(500); $("#divsunset").fadeIn(500); }); $("#trigger2").mouseover(function() { $(".contentdiv").addClass("inactive"); $("#divwinter").removeClass("inactive"); $(".inactive").fadeOut(500); $("#divwinter").fadeIn(500); }); $("#trigger3").mouseover(function() { $(".contentdiv").addClass("inactive"); $("#divbh").removeClass("inactive"); $(".inactive").fadeOut(500); $("#divbh").fadeIn(500); }); $("#trigger4").mouseover(function() { $(".contentdiv").addClass("inactive"); $("#divwl").removeClass("inactive"); $(".inactive").fadeOut(500); $("#divwl").fadeIn(500); }); }); &lt;/script&gt; &lt;style&gt; #divsunset { position: absolute; top: 5px; left: 5px; } #divwinter { position: absolute; top: 5px; left: 5px; } #divbh { position: absolute; top: 5px; left: 5px; } #divwl { position: absolute; top: 5px; left: 5px; } #links { position: absolute; top: 800px; left: 700px; } .inactive { } &lt;/style&gt; </code></pre> <p> </p> <p><br /></p> Show Sunset Show Winter Show Blue Hills Show Waterlillies <p> </p> <hr> <p>Thank you Matt, TM and kRON, your responses really helped.</p> <p>I dont feel I explained myself totally, but TM provided the answer I was looking for.</p> <p>I wanted to follow DRY and the code TM provided helped me best this time since it did not require for me to alter my markup, just the jQuery code.</p> <p>Again, thanks a lot. Its amazing how quickly I got the answer. Keep up the great work.</p>
 

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