NosiaD
NosiaD

Reputation: 597

How do I remove a certain div based on the class name and attr name?

I want to ask if how to remove a certain DIV using the class name and ATTR name?...

$(".deletePost").click(function(){ 
        var delPostRelVal = $(".deletePost").attr("rel");
        $.post(loadUrl, {dpost: $(this).attr("rel")},
           function(data) {
           if( $(".perMes").attr("rel") == delPostRelVal ) {
                  $(".perMes").remove().fadeOut(500);
           }
           });
});

The code is working, however the ".perMes" will remove all my PHP that contains ".perMes" i just want to limit the removal of ".perMes" using the attr("rel")

and if the code like this...

if( $(".perMes").attr("rel") == delPostRelVal ) {
    $(".perMes").attr("rel").remove().fadeOut(500);
}

then the ajax doesnt work...or to update itself..anyone can help me or teach me other alternative code...I appreciated your works here guys...i hope you can help me to solve this..

Upvotes: 2

Views: 132

Answers (2)

Ryan
Ryan

Reputation: 1557

    $(".perMes").filter(function() {
        return this.attr('rel') === delPostRelVal;
    }).remove().fadeOut(500);

Upvotes: 1

Chris
Chris

Reputation: 4471

You can use the attribute selector.

$(".perMes[rel='" + delPostRelVal + "']").remove().fadeOut(500);

Upvotes: 3

Related Questions