我的问题很直接。
下面的代码正确记录“this”,并打印出所需的子元素:
console.log( $(this).children()[0] );
印刷:
<span>test result</span>
尝试检索其值会引发异常。我在用着:
$((this).children()[0]).val()
哪个抛出:
Property 'children' of object [object HTMLAnchorElement] is not a function
我的语法有什么问题?
HTML:
<li>
<a href="#">
<span>example 1</span>
<span>example 1 sibling</span>
</a>
</li>
<li>
<a href="#">
<span>example</span>
<span>example 2 sibling</span>
</a>
</li>
<li>
<a href="#">
<span>example</span>
<span>example 3 sibling</span>
</a>
</li>
<li>
<a href="#">
<span>example</span>
<span>example 4 sibling</span></a>
</li>