如何从 $(this) 获取子元素?
例如,我如何定位 this 对象中的 span 元素?
最佳答案
您可以使用find
方法:
$(this).find("span");
这将找到作为 this
引用的元素的后代的所有 span
元素。
如果你只关心直系 child ,你可以使用 children
相反:
$(this).children("span");
或者,您可以使用 this
作为选择器的上下文:
$("span", this);
如果 this
是包含一组同级元素的 jQuery 对象(因此 span
不是后代),则需要另一种解决方案。在这种情况下,您需要 filter
:
$(this).filter("span");
关于javascript - jQuery 中此对象的目标子元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8857848/