Rol*_*and 1 html css jquery jquery-plugins
我有这个代码:
<div id="popupContactIMG_4179" class="xxxx">
<a id="popupContactCloseIMG_4179">x</a>
<img alt="" src="../IMG_4179.jpg" id="id1">
</div>
Run Code Online (Sandbox Code Playgroud)
我想得到鼠标点击img内的id :<a><a>
$("a[id^=popupContactClose]").click(function(){
var qwerty = $(this+" img").attr("id");
}
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
最简单的方法是使用next(如img下面的兄弟):
$("a[id^=popupContactClose]").click(function(){
var qwerty = $(this).next().attr("id");
});
Run Code Online (Sandbox Code Playgroud)
或者,您似乎尝试执行的操作是将this作为上下文的父项传递给jQuery:
$("a[id^=popupContactClose]").click(function(){
var qwerty = $("img", $(this).parent()).attr("id");
});
Run Code Online (Sandbox Code Playgroud)