当你有多个具有相同名称的类时,使用jQuery选择一个特定的类

时间:2014-01-29 14:27:21

标签: javascript php

我正在使用PHP创建一个输出最新上传图像的图库:

while($row = mysqli_fetch_array($result))
{
echo  "<div class='ram-bild'>
<div class='nailthumb-container square'>
<a href='bigpicture.php?id=" . $row['pic_name']  . "'><img src=upload/thumb/" .$row['pic_name']  . "></img></a>
</div>
</div>";
}

$ result只是从我的表中获取id。

现在,我想使用jQuery在鼠标上方显示文本。

像这样:

没有鼠标: 将鼠标悬停在:http://piclair.com/data/0ooqy.jpg 但由于所有图像都具有相同的类,我将如何使用jQuery?

1 个答案:

答案 0 :(得分:2)

使用this

的实例
$(".ram-bild").hover(function() {
    $(this)... //targets the above element on mouseenter
}, function() {
    $(this)... //targets above element on mouseleave
});