-1

I have (I believe)a very simple problem, but can't figure out what is wrong. the code will tell everything:

$(".all-products h3").mouseenter(function () {
    $(this).siblings('p').slideDown(200);
}).mouseleave(function () {
    $(this).siblings('p').slideUp(500);
});

and this is html:

<a title="xxx" href="#">
    <img src="1.jpg"/>
    <p>description</p>
    <h3>header3</h3>
</a>

This one works fine, but why doesn't it work when I replace in jquery the h3 with a, so it doesnt work this way below:

$(".all-products a").mouseenter(function () {
    $(this).siblings('p').slideDown(200);
}).mouseleave(function () {
    $(this).siblings('p').slideUp(500);
});
Piotr Ciszewski
  • 1,691
  • 4
  • 30
  • 53

4 Answers4

2

a is not a sibling of p, it is the parent of p. Try using .children('p') or .find('p') instead (the former is more specific).

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
1
$(".all-products a").mouseenter(function () {
    $(this).find('p').slideDown(200);
}).mouseleave(function () {
    $(this).find('p').slideUp(500);
});

Siblings of a would exist at the same level in the DOM. In your case you want to .find() the elements or call children(). either way.

Kai Qing
  • 18,793
  • 5
  • 39
  • 57
1

Cause you are using siblings.

Try this:

$(".all-products a").mouseenter(function(){
          $('p', this).slideDown(200);
           }).mouseleave(function() {
          $('p', this).slideUp(500);
        });
rkrdo
  • 196
  • 8
1

Well it would seem the major problem is that that p element is not sibling to the a. You would need to replace siblings() with children()

Mike Brant
  • 70,514
  • 10
  • 99
  • 103