Jquery 拒绝使用正确的语法选择元素

发布于 2024-09-19 11:34:06 字数 788 浏览 2 评论 0原文

嗨,我想删除一个链接,我得到了这个代码,

$(document).ready(function(){
 $(".features-list a").removeAttr("href");

并且没有选择

<ul class="features-list">
<li id="f1"><a href="http://www.somepage.com"Link that stops being a link</a></li>
</ul>

我添加了 id 的元素来尝试看看我是否可以做到这一点

 $(".features-list#f1").removeAttr("href");

不起作用,我必须添加其余的 jquery 代码正在正确执行,我就是想不通这个问题。这就是我尝试删除的链接

 $("#f1").removeAttr("href");
 $(".features-list > a").removeAttr("href");
 $(".features-list li ").removeAttr("href");
 $(".features-list").children(a).removeAttr("href");

 $(".features-list").Attr("href","#");

但jquery拒绝选择它 我做错了什么?

Hi i wanted to remove a link and i got this code

$(document).ready(function(){
 $(".features-list a").removeAttr("href");

And is not selecting the element

<ul class="features-list">
<li id="f1"><a href="http://www.somepage.com"Link that stops being a link</a></li>
</ul>

I added the id to try and see if i could do this

 $(".features-list#f1").removeAttr("href");

Is not working, i must add that the rest of the jquery code is being correctly executed, i just can't figure this one out. This is all i tried to remove the link

 $("#f1").removeAttr("href");
 $(".features-list > a").removeAttr("href");
 $(".features-list li ").removeAttr("href");
 $(".features-list").children(a).removeAttr("href");

I even tried

 $(".features-list").Attr("href","#");

But jquery refuses to select it
What am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎樣才叫好 2024-09-26 11:34:06

您的链接似乎已损坏(缺少结束标记 >):

<a href="http://www.somepage.com"Link that stops being a link</a>

它应该是:

<a href="http://www.somepage.com">Link that stops being a link</a>

另外 $(".features-list#f1").removeAttr("href"); 不起作用,因为 li 上没有定义 href 属性,并且此 li 没有 class="features-list"

$('#f1 a') 选择包含 id="f1" 的元素内的链接(这是您的 li 中的案件)。 $(".features-list a").removeAttr("href") 也应该有效。

这是一个工作示例

Your link appears broken (it's missing the closing tag >):

<a href="http://www.somepage.com"Link that stops being a link</a>

It should be:

<a href="http://www.somepage.com">Link that stops being a link</a>

Also $(".features-list#f1").removeAttr("href"); didn't work because there's no href attribute defined on the li and this li has no class="features-list".

$('#f1 a') selects a link which is inside an element with id="f1" (which is the li in your case). $(".features-list a").removeAttr("href") should also work.

Here's a working example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文