Thursday, April 21, 2011

Adding action to a delete event in jQuery

How can you add the class red to the class question_body when the question is removed?

JS in HEAD

jQuery('a.delete_question').live('click', function(){

    jQuery.post('/codes/handlers/delete_a_question.php', 
        { question_id: jQuery(this).attr('rel') }, 
        function(){
            $(.question_body).addClass("red");       // problem here
            alert ("Question was removed");
        })
});

The following URL generated by PHP should activate the action

    echo ("<a href='#'"
            . "class='dulete_question'"
            . " rel='" . $answer_id . "'>flag</a>"
        );

The problem is similar as this one. It suggests me that addClass -command should be correct and that the problem is in the use of it inside the function.

From stackoverflow
  • Change this:

     $(.question_body).addClass("red");
    

    To this:

     $(".question_body").addClass("red");
    

    Also make sure you have a CSS class called "red" defined.

    You can test this by moving the alert to before the addClass line, rather than after it.

    Masi : **Thank you very much for your answer!**

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.