如何更改不包含';我没有使用JavaScript的id或类
我无法访问承载代码片段的html文档。锚链接不正确,用户无法访问信息和工具。锚定链接位于如何更改不包含';我没有使用JavaScript的id或类,javascript,html,Javascript,Html,我无法访问承载代码片段的html文档。锚链接不正确,用户无法访问信息和工具。锚定链接位于标记的内部,该标记位于表的内部,该表位于div的内部。现在div是唯一有ID的东西,我不能将jQuery添加到这个页面包装器中,因为它已经应用于1000多个页面,所以我不想破坏任何东西 HTML: 但我不知道如何使用JavaScript实现这一点 我在想,如果有办法向锚定链接添加类或id,我可以这样做 var pcfaq = document.getElementById('wrongLinkOne'); p
标记的内部,该标记位于表的内部,该表位于div的内部。现在div是唯一有ID的东西,我不能将jQuery添加到这个页面包装器中,因为它已经应用于1000多个页面,所以我不想破坏任何东西
HTML:
但我不知道如何使用JavaScript实现这一点
我在想,如果有办法向锚定链接添加类或id,我可以这样做
var pcfaq = document.getElementById('wrongLinkOne');
pcfaq.href= "[[S8:PC_FAQ_updated.html]]"
(S8呈现html链接)
谢谢你的帮助 使用document.queryselectoral()
查找td
中的所有a
标记。在它们上面循环,检查文本是否包含所需内容,并更改href
document.querySelectorAll("td a").forEach(el => {
if (a.textContent.includes("As part of your registration you will receive update emails and support from this program.")) {
a.href = "[[S8:PC_FAQ_updated.html]]";
}
});
使用document.querySelectorAll()
查找td
中的所有a
标记。在它们上面循环,检查文本是否包含所需内容,并更改href
document.querySelectorAll("td a").forEach(el => {
if (a.textContent.includes("As part of your registration you will receive update emails and support from this program.")) {
a.href = "[[S8:PC_FAQ_updated.html]]";
}
});
对不起,ErrorLinkOne
id在哪里?只需使用document.querySelector
,使用合适的选择器并修改元素。@FrancoScarpa抱歉,错误链接只是我编造的一个例子,如果我能弄明白的话,我会做什么。抱歉,但是错误链接id在哪里?只需使用文档.querySelector
,使用适当的选择器,并根据您的需要修改元素。@FrancoScarpa抱歉,错误的LinkOne只是我编造的一个例子,如果我能弄明白的话,我会做的。太棒了!非常感谢你。我在谷歌上搜索了“如何使用javascript更改锚链接”和“使用javascript查找包含文本的元素”,但我找不到任何对我有意义的东西,哈哈。这是完美的Barmar谢谢你真棒!非常感谢你。我在谷歌上搜索了“如何使用javascript更改锚链接”和“使用javascript查找包含文本的元素”,但我找不到任何对我有意义的东西,哈哈。这是完美的Barmar谢谢
document.querySelectorAll("td a").forEach(el => {
if (a.textContent.includes("As part of your registration you will receive update emails and support from this program.")) {
a.href = "[[S8:PC_FAQ_updated.html]]";
}
});