我有一个类似的布局:

<div id="..."><img src="..."></div>

并希望使用jQuery选择器在单击时选择div中的子img。

为了得到div,我有一个选择器:

$(this)

如何使用选择器获取子img?


当前回答

不知道DIV的ID,我想您可以这样选择IMG:

$("#"+$(this).attr("id")+" img:first")

其他回答

不知道DIV的ID,我想您可以这样选择IMG:

$("#"+$(this).attr("id")+" img:first")

尝试以下代码:

$(this).children()[0]

如果DIV标记后面紧跟IMG标记,则还可以使用:

$(this).next();

此外,这也应该起作用:

$("#id img")

你可以使用

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
 $(this).find('img');
</script>