views:

40

answers:

3

hello. for example ive got a div like:

<div class="y1">
<img src="i/o.png" />
</div>

and

<!-- pre load -->
<div class="p1" style="display:none">
<h5 class="ob">Title</h5>
<img class="ob" src="i/ob.png" />
<small class="ob">Description</small>
<a href="#" class="oyna">PLAY</a>
</div>

and this jquery

<script type="text/javascript">

$("div.y1").hover(
  function () {
    $('div.p1').slideDown('slow', function() {
  });
  }
);
</script>

my question is how can i repeat it for 12 times. i mean when i hover on y1, show p1, y2 => p2, y3 => p3 ... y12 => p12. i hope you guys understand me. thank you so much!!!!

+1  A: 

Should look like:

$(function(){
       $('div[class^=y]').hover(function(){
        var self   = $(this),
            number = this.className.slice(1);

        $('div.p' + number).slideDown('slow', function() {
        });
    }, function() {
        var self   = $(this),
            number = this.className.slice(1);

        $('div.p' + number).slideUp('slow', function() {
        });
    });
});

Example: http://www.jsfiddle.net/Q5Ug2/

jAndy
@jAndy, you don't really need the `self` parts..
Gaby
this works very well. but now I have to ask a new question... I need it to keep slided down the p# div. because there is a link to be clicked. i want it to slide up "only" when hover another y# div. thank you...
Ali
A: 

Do things a bit differently..

Use ID's for the p# and y# series indicators.
On your DIV tags for the p# series, add a title of the y# series.. so <div id="p1" title="y1">
On your DIV tags for the y# series, add a class.. <div id="y1" class="hoverMe">

$('div.hoverMe').hover( function() {  
    $('[title=' + $(this).attr('id') + ']').slideDown('slow');
});
Fosco
A: 

I'm going to assume that your y# divs are inside a div with the id container. Secondly, I'm going to assume that none of your y# divs have any other classes applied to them.

$('#container').delegate('div[class^=y]','mouseenter', function(){
    $('div.p' + this.className.slice(1)).slideDown('slow');
}).delegate('div[class^=y]', 'mouseleave', function(){
    $('div.p' + this.className.slice(1)).slideUp('slow');
});

This uses delegate to avoid the cost of binding to multiple DOM elements.


Edit To hide the p# div on hovering on another element, you can use this code.

$('#container').delegate('div[class^=y]','mouseenter', function(){
    $('div.p' + this.className.slice(1)).slideDown('slow').siblings().slideUp();
});
lonesomeday
this works very well too. but now I have to ask a new question... I need it to keep slided down the p# div. because there is a link to be clicked. i want it to slide up "only" when hover another y# div. thank you...
Ali
@Ali Edited per request.
lonesomeday
and now when i hover on y#, #container is sliding up and im not able to see another y# elements :/
Ali
Whoops, I forgot to mention -- this requires wrapping all the `p#` divs in a container div.
lonesomeday
see here: http://musicontheave.com/nr/ its not working. hover to small any of small icons at the middle circle.
Ali
As I tried to explain, you need to wrap all the `p#` classes in a container. See http://pastebin.com/jyTV2BDJ
lonesomeday
-.- when I do that hover is not working anymore. no actions.
Ali
Getting 403 Forbidden when trying to load the page.
lonesomeday
well I moved script code to end of the document and it works very fine now. thank you so much :)
Ali