jquery class and this selector
I am trying to find the correct jquery way to select only a certain class within the currently active div:
$('.imageScroll').mouseover(function() {
$('.开发者_Python百科descBox').filter(this).show(500);
});
markup:
<li>
<div class="descBox"></div>
</li>
<li>
<div class="descBox"></div>
</li>
From what I understand, you should try $('.descBox', this)
.
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);
You mean this:
alert($('.descBox').attr('class'));
$(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>
精彩评论