Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to remove the id attribute from this image:

<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!

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

like image 808
getaway Avatar asked Jan 04 '11 01:01

getaway


People also ask

How remove data attribute value in jQuery?

To prevent this, use . removeAttr() alongside . removeData() to remove the data- attribute as well.

How remove selected attribute from option in jQuery?

$("#mySelect option:selected"). each(function () { $(this). removeAttr('selected'); });

How do you add or remove HTML attribute in jQuery?

To add and remove HTML attributes with jQuery, use the addClass() and removeClass() method.


2 Answers

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.

like image 65
user113716 Avatar answered Sep 21 '22 08:09

user113716


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

$('#thumb').removeAttr('id'); 
like image 38
zzzzBov Avatar answered Sep 21 '22 08:09

zzzzBov