简体   繁体   English

如何使用 jQuery 从 div 中删除 id 属性?

[英]How to remove an id attribute from a div using jQuery?

I want to remove the id attribute from this image:我想从此图像中删除 id 属性:

<img width="270" class="thumb" id="thumb" height="270" src="img/1_1.jpg" />

I tried doing this:我试过这样做:

$('img#thumb').RemoveAttr('id','none');

But it is not removing the ID!但它并没有删除ID!

EDIT:编辑:

$('img#thumb').attr('src', response);
$('img#thumb').attr('id', 'nonthumb');

This deosnt load the picture, or in this case the src, But when I remove the id attribute, it works fine这 deosnt 加载图片,或者在这种情况下加载 src,但是当我删除 id 属性时,它工作正常

The capitalization is wrong, and you have an extra argument. 大写是错误的,你还有一个额外的论点。

Do this instead: 改为:

$('img#thumb').removeAttr('id');

For future reference, there aren't any jQuery methods that begin with a capital letter. 为了将来参考,没有任何以大写字母开头的jQuery方法。 They all take the same form as this one, starting with a lower case, and the first letter of each joined "word" is upper case. 它们都采用与这个相同的形式,从小写开始,每个加入“单词”的第一个字母是大写。

我不确定你在看什么jQuery api ,但你应该只需要指定id

$('#thumb').removeAttr('id');

You can remove attribute with the following您可以使用以下命令删除属性

$("#my_id").prop("id", "");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM