Solved

Jquery onhover

Posted on 2012-03-10
11
372 Views
Last Modified: 2012-03-10
Hello experts.
I need help with the onhover function using the code below
<style type="text/css">
.hidden{display:none;}
</style>
<div id="featureddiv">
 <div class="flleft imagelayout" >
  <div class="front">
   <a href="" rel="" class="resultslink">
    <img src="test.jpg" alt="" name="" width="80" height="80">
   </a>
  </div>
  <div class="back hidden">
   <a href="" rel="" class="resultslink">blablabla</a>
  </div>
 </div>
 <div class="flleft imagelayout" >
  <div class="front">
   <a href="" rel="" class="resultslink">
    <img src="test.png" alt="" name="" width="80" height="80">
   </a>
  </div>
  <div class="back hidden">
   <a href="" rel="" class="resultslink">blablablabla</a>
  </div>
 </div>
</div>
<script type="text/javascript">
$(document).ready(function () {
  	$('#featureddiv .imagelayout').hover(
        function () {
            $(this).find('div .front').hide();
        },
        function () {
            $(this).find('div .back').show();
        }
    );
});
</script>

Open in new window

I want to show the back div onhover.
Any help?
0
Comment
Question by:Panos
  • 7
  • 3
11 Comments
 
LVL 11

Expert Comment

by:maeltar
ID: 37704457
This works...

<script type="text/javascript">
$(document).ready(function () {
    
    $('#featureddiv .imagelayout').mouseenter(function(){
        $('.front').hide();
        $('.back').show();
}).mouseleave(function(){
       $('.front').show();
        $('.back').hide();
  });
    
 
});
</script>

Open in new window


example here :

http://sdparkes.co.uk/ee_ex/hover_div.php
0
 
LVL 2

Author Comment

by:Panos
ID: 37704698
Hi maeltar
The code needs a little correction to show only one div (the onhover div) and not all the hidden divs.
0
 
LVL 11

Expert Comment

by:maeltar
ID: 37704702
Not sure what you mean ?

The code hides divs with a class of from, and shows with a class of back, then on mouseleave it reverses it..
0
 
LVL 2

Author Comment

by:Panos
ID: 37704712
featureddiv is the main div
each imagelayout  div has two divs :
1. one that is shown
2. one that is hidden

I want to show the hidden one (and the shown) when i rollover the one that is shown.
I hope you understand what i'm trying to do
0
 
LVL 2

Author Comment

by:Panos
ID: 37704713
....(and hide the shown)....
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 11

Expert Comment

by:maeltar
ID: 37704719
So you don't want it to revert back to it's original state when the mouse leaves ?
0
 
LVL 2

Author Comment

by:Panos
ID: 37704727
You are right. I missed that.
It must revert back .
0
 
LVL 2

Author Comment

by:Panos
ID: 37704860
Finally this code is working for me:
$('#featureddiv .imagelayout').mouseenter(function(){
        $(this).find('.front').hide();
        $(this).find('.back').show();
}).mouseleave(function(){
        $(this).find('.front').show();
        $(this).find('.back').hide();
  });
0
 
LVL 15

Accepted Solution

by:
StingRaY earned 500 total points
ID: 37704915
The problem is your selector.

When you say "div .front" (a space between div and .front), it means you are looking for an element which class "front" under "div". But if you look for a div which contains class named "front", you should write "div.front" (no space).
0
 
LVL 2

Author Comment

by:Panos
ID: 37704941
you are right
thank you for your help.
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 37704947
thank you
regards
panos
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now