views:

48

answers:

4

I am trying to find the correct jquery way to select only a certain class within the currently active div:

$('.imageScroll').mouseover(function() {
    $('.descBox').filter(this).show(500);
});

markup:

<li>
<div class="descBox"></div>
</li>
<li>
<div class="descBox"></div>
</li>
+1  A: 

You mean this:

alert($('.descBox').attr('class'));
Sarfraz
+2  A: 

From what I understand, you should try $('.descBox', this).

Mewp
+1  A: 
$(this).filter(".descBox").show(500);

Usually you use filter to do slightly more complicated things. For example if you changed the background of all the divs inside "this" parent, and then you want to add a border to only the "descBox" class within all the divs with descBox classes inside "this".

Something like this (essentially lifted from the manual):

 $("div", this).css("background", "#c8ebcc")
               .filter(".descBox")
               .css("border-color", "red"); 

Maybe in this context:

<div>
    <div></div>
    <div class="descBox"></div>
    <div class="descBox"></div>
    <div class="descBox"></div>
    <div class="descBox"></div>
    <div></div>
</div>
<script>
$("div").click(function() 
{    
    $("div", this).css("background", "#c8ebcc")
                  .filter(".middle")
                  .css("border-color", "red");
});
</script>
Peter Ajtai
+2  A: 

If you are trying to show the divs with .descBox that are inside the this element (which ever that is) then use

$('.descBox', this).show(500);
Gaby
Thanks to all, I really should know my basic jquery syntax.
kalpaitch