Jquery 拒绝使用正确的语法选择元素
嗨,我想删除一个链接,我得到了这个代码,
$(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的链接似乎已损坏(缺少结束标记
>
):它应该是:
另外
$(".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
>
):It should be:
Also
$(".features-list#f1").removeAttr("href");
didn't work because there's nohref
attribute defined on theli
and this li has noclass="features-list"
.$('#f1 a')
selects a link which is inside an element withid="f1"
(which is theli
in your case).$(".features-list a").removeAttr("href")
should also work.Here's a working example.