Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to chain javascript to when hovering element to change picture of an element and display block third element
    primarykey
    data
    text
    <p>Hello guys i am trying to make something like a slider, i have 4 buttons which when pressed i want to change the main picture and show the content for each picture, after a bit of browsing and testing i managed the get the image to change on hover however i am having difficulty getting the content div to change i was trying to use the display none for the other content divs and block for the active one however i can't chain the whole thing, the best i could do was this </p> <pre><code> $('#changeImage').attr('src', 'pic1.png'); }, function() { $(".content.one").css("display", "block"); }, function() { $(".content.two").css("display", "none"); }, function() { $(".content.three").css("display", "none"); }, function() { $(".content.four").css("display", "none"); } ) </code></pre> <p>however only the .content.one changes and only when i move my mouse out. I hope i made my self clear my English is not that good if i can help clarify anything feel free to ask.</p> <p>here is the whole java script</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { $("ul li:nth-child(1)").hover( function () { $('#changeImage').attr('src', 'pic1.png'); }, function() { $(".content.one").css("display", "block"); }, function() { $(".content.two").css("display", "none"); }, function() { $(".content.three").css("display", "none"); }, function() { $(".content.four").css("display", "none"); } ); $("ul li:nth-child(2)").hover( function () { $('#changeImage').attr('src', 'pic2.png'); } ); $("ul li:nth-child(3)").hover( function () { $('#changeImage').attr('src', 'pic3.png'); } ); $("ul li:nth-child(4)").hover( function () { $('#changeImage').attr('src', 'pic4.png'); }, function() { $(".content.one").css("display", "none"); }, function() { $(".content.two").css("display", "none"); }, function() { $(".content.three").css("display", "none"); }, function() { $(".content.four").css("display", "block"); } ); }); &lt;/script&gt; </code></pre> <p>and the whole html</p> <pre><code>&lt;div id="wrapper"&gt; &lt;img src="clear.png"&gt; &lt;ul id="side-bar"&gt; &lt;li class="one"&gt;&lt;a href="#"&gt;&lt;img src="1-1.png" onmouseover="this.src='1-2.png'" onmouseout="this.src='1-1.png'"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="two"&gt;&lt;a href="#"&gt;&lt;img src="2-2.png"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="three"&gt;&lt;a href="#"&gt;&lt;img src="3-1.png" onmouseover="this.src='3-2.png'" onmouseout="this.src='3-1.png'"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="four"&gt;&lt;a href="#"&gt;&lt;img src="4-1.png" onmouseover="this.src='4-2.png'" onmouseout="this.src='4-1.png'"&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="image"&gt;&lt;img id="changeImage" src="pic1.png"&gt;&lt;/div&gt; &lt;div id="content-wrapper"&gt;&lt;img src="content.png"&gt;&lt;/div&gt; &lt;div class="content one"&gt;&lt;p&gt;content 1&lt;/p&gt;&lt;a href="#" class="more"&gt;read more...&lt;/a&gt;&lt;/div&gt; &lt;div class="content two"&gt;&lt;p&gt;content 2&lt;/p&gt;&lt;a href="#" class="more"&gt;read more...&lt;/a&gt;&lt;/div&gt; &lt;div class="content three"&gt;&lt;p&gt;content 3&lt;/p&gt;&lt;a href="#" class="more"&gt;read more...&lt;/a&gt;&lt;/div&gt; &lt;div class="content four"&gt;&lt;p&gt;content 4&lt;/p&gt;&lt;a href="#" class="more"&gt;read more...&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    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