我有一个代表 DIV 的 jQuery 对象:
$rel = $('#rel_'+rel.id);
在该 DIV 中,有一个按钮,我的自定义属性“rid”设置为 rel.id
我需要选择该按钮,它的工作原理如下:
$("[rid='"+rel.id+"']").html();
但我认为这不是最快的解决方案,因为它需要解析整个 DOM,并且因为我知道按钮始终位于 DIV 内,所以我可以避免这种情况。
我尝试使用以下代码:
$rel.children("[rid='"+rel.id+"']").html();
但这没有用。
感谢您的帮助。
最佳答案
如果它可能不是直系子代,您将需要 find
而不是 children
(只查看直接子级):
$rel.find("[rid='"+rel.id+"']").html();
关于jquery - 通过属性值获取元素的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16117883/