Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To have `removeID` for jQuery like `removeClass`

Tags:

jquery

How can you remove the attribute id by jQuery?

jQuery('a.no_flag_question').live('click', function(){
    jQuery.post('/codes/handlers/no_flag_question.php', 
        { question_id: jQuery(this).attr('rel') });
            $(".question_box").removeClass("yellow");   // problem here
            alert ("Question is now not spam.");
});

This code should remove the following yellow -attribute in

<div id="yellow" class="question_box">

However, this does not work. The reason is very likely the function removeClass. I apparently use wrong function, since I want to use the ID.

like image 697
Léo Léopold Hertz 준영 Avatar asked Aug 23 '09 02:08

Léo Léopold Hertz 준영


2 Answers

$('.question_box').removeAttr('id')

More info at http://docs.jquery.com/Attributes/removeAttr

like image 146
meder omuraliev Avatar answered Sep 26 '22 02:09

meder omuraliev


removeClass only exists because class is a multi-valued attribute... if you have a <div class="one two three"> and you call .removeClass("two") on it, it should end up with class="one three". addClass and removeClass exist to save you from doing all that work yourself. id isn't special in that way, so you just access it with attr.

like image 22
hobbs Avatar answered Sep 23 '22 02:09

hobbs