[英]jquery - how can I select element after '.first()' using?
How can I select html tag
after using jquery function called .first()
? 使用名为
.first()
jquery函数后,如何选择html tag
?
HTML 的HTML
<html>
<head> </head>
<body>
<div>
<a>
<img id="#hello">
</a>
</div>
<div></div>
</body>
</html>
JS (JQuery) JS(jQuery)
var elemFirst = $(div).first();
var selectImg = elemFirst.$('img#hello');
// var selectImg = elemFirst.find('img'); <- It working but I want to select manual
selectImg.addClass('some-css');
With Respect 尊重地
You can use find()
: 您可以使用
find()
:
var selectImg = elemFirst.find('img#hello');
But you have an id
of the image, so, you just can do this: 但是您具有图像的
id
,因此,您可以执行以下操作:
$('img#hello')
Because id
is unique. 因为
id
是唯一的。
You can use $('child','parent')
selector, 您可以使用
$('child','parent')
选择器,
var elemFirst = $('div').first();
var selectImg = $('#hello',elemFirst); //or just $('img',elemFirst);
Also, your id has a #
, it should be just id="hello"
. 另外,您的ID有一个
#
,应该只是id="hello"
。
If you need to keep this value in Id, use 如果您需要将此值保留在ID中,请使用
var selectImg = $('img[id="#hello"]',elemFirst);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.