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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4589900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 13:07:03  来源:igfitidea点击:

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

javascriptjqueryhtmlimage

提问by getaway

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

这会加载图片,或者在这种情况下加载 src!但是当我删除 id 属性时,它工作正常

回答by user113716

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. 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 方法。它们都采用与这个相同的形式,以小写开头,并且每个连接的“单词”的第一个字母都是大写。

回答by zzzzBov

I'm not sure what jQuery apiyou're looking at, but you should only have to specify id.

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

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