使用find查找选择器的子级

Using find to find children of selector?

本文关键字:选择器 find 查找 使用      更新时间:2023-09-26

HTML:

<div class="container>
    <a href=""></a>
</div>

如何使用find获取锚点?我试过:

html = $(html);
html.find('.container a').attr('href', 'xyz');

运气不好。

FYI html var是一个ajax调用返回的html块。

它惊艳了

$( html ).children( ".container a" ).attr( 'href', 'xyz' );

html变量本身具有容器类。所以,没必要再找了。你可以使用

html = $(html);
html.find('a').attr('href','xyz');

希望这能奏效!!