Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery. Remove element by attribute name. How?

Tags:

jquery

Is there a way to remove a DIV based on it's custom attribute comment_id?

I have the following code but it does not quite work yet.

<script type="text/javascript">
    $('.delete_comment').live('click', function() {
        // Url we request data from
        $.get( "http://www.site.com/pages/delete/user_comment.php",
        // Url parameters to send 
        {id:$(this).attr('comment_id'),c:'yes'},
        // Output data from php file generated by PHP echo.
        function(data)
        { 
            var comment_id = $(this).attr('comment_id').val();
            //alert(comment_id);
            if (comment_id == data) {

                $(this).remove();

            }

        });

    });
</script>
like image 506
suchislife Avatar asked Oct 03 '11 06:10

suchislife


People also ask

How do I remove a specific attribute in jQuery?

To remove an attribute from each tag using jQuery, use the removeAttr() method and use the Universal Selector.

What jQuery method is used to completely remove attributes from elements?

The removeAttr() method removes one or more attributes from the selected elements.


1 Answers

Yes, possible

http://api.jquery.com/category/selectors/
http://api.jquery.com/jQuery.each/

$('div[comment_id="value"]').remove();
like image 97
Marek Sebera Avatar answered Oct 16 '22 07:10

Marek Sebera