gpt4 book ai didi

javascript - 使用 javascript 删除 html

转载 作者:行者123 更新时间:2023-11-28 13:17:52 25 4
gpt4 key购买 nike

我正在尝试使用 javascript(无 jquery)删除整个 html block 。

来源

 <li uib-dropdown="" class="dropdown hidden-xs">
<a uib-dropdown-toggle="" class="dropdown-toggle pointer" "="" aria-haspopup="true" aria-expanded="false">
<img width="22" title=" - xyz@gmail.com" height="22" class="img-rounded profile-img" src="https://www.gravatar.com/avatar/edft80b9a51f775c8ee562ca89345318b"> &nbsp;
<!-- <b class="caret"></b> -->
<i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu small-dropdown-menu">
<li><a href="https://app.example.com/#/account">Account</a></li>
<li><a href="https://app.example.com/#/account/billing">Billing</a></li>
<li><a href="https://app.example.com/#/account/team">Team</a></li>
<li><a href="https://app.example.com/#/account/plans">Plans</a></li>
<li class="hidden-lg"><a class="pointer" title="Ask us a question, report a bug or suggest a feature!" href="mailto:help@example.com">Contact</a></li>
<hr>
<li><a target="_self" href="https://app.example.com/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
</ul>
</li>

期望的结果整个代码块应该被删除

我的尝试

document.getElementsByClassName('dropdown hidden-xs').innerHTML = '';

最佳答案

getElementsByClassName 返回类似数组的对象,因此您需要通过索引访问元素:

document.getElementsByClassName('dropdown hidden-xs')[0].innerHTML = '';

关于javascript - 使用 javascript 删除 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36105660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com