Solved

Jquery onhover

Posted on 2012-03-10
11
368 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to dynamically set the form action using jQuery.

757 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

21 Experts available now in Live!

Get 1:1 Help Now