srm*_*ark 0 jquery css-selectors
我一遍又一遍地阅读文档,我无法理解为什么这不起作用:
从函数内部调用以下内容:
alert($(this).parent().parent().html());
Run Code Online (Sandbox Code Playgroud)
返回看起来像这样的东西:
<div class="something1">
    <div class="whereThisStarted">stuff</div>
    </div>
<div class="something2">stuff</div>
<div class="somethingSpecial">stuff</div>
<div class="something4">stuff</div>
Run Code Online (Sandbox Code Playgroud)
我想得到"特别的东西".在我看来,以下任何一个都应该工作,但它们都返回null.
alert($(this).parent().parent().children(".somethingSpecial").html());
alert($(this).parent().parent().filter("div.somethingSpecial").html());
Run Code Online (Sandbox Code Playgroud)
这有什么问题?
谢谢
如果你真的必须按照你想要的方式而不是TStamper的表现,请试试这个:
alert($(this).parent().parent().find("div.somethingSpecial").html());
Run Code Online (Sandbox Code Playgroud)