ajax filter tag from controller call and fadeout with remove children tagcall

Subject:

another long process to add a filtered element from the controller echo with ajax request, then fade out success response and have to remove the new inserted tag with attributes so you can cycle this function several times.

2014-12-07 13:33:29gstlouis

success: function(data){
            $('.sr-only').trigger('click');
            $('.successSaved').html($(data).filter('#replied').html());
            //$('.successSaved').css('background-color', 'green');
            $('.successSaved').addClass('success');

            /*$('.successSaved').css({
                'background-color': 'green',
                'color': "white",
                'padding' : '5px',
                'border-radius' : '10px'
            });*/
            //$('.successSaved').css({ background-color:'green', color:'white' });

            $('.successSaved').fadeOut('slow');

            setTimeout(function(){
                $('.successSaved p').remove();
                $('.successSaved').removeClass('success');
                $('.successSaved').removeAttr('style');
                $('.successSaved').css('background-color', 'white');
            }, 1500);
            
        },
        error: function(data){
            alert('The time was not updated, please contact this application Administrator');
            $('.sr-only').trigger('click');
        }

gstlouis
vote
2014-12-07 13:33:49

The above works fine when you filter top level tags.  If you need to select children or descending tags you use find()

references:

http://stackoverflow.com/questions/4245231/how-do-i-filter-the-returned-data-from-jquery-ajax

If you want to select the top-level elements = elements that are direct children of BODY - in this example: #wrap or #tooltip - then you have to use filter().

If you want to select other elements - in this example: #header, h1, #body, ... - then you have to use find().

I you don't know whether your element is a child of BODY or not, you could use this "hack":

$("<div>").html(data).find( selector );

By using this work-around, you always get the elements via find().

gstlouis
vote
2015-02-25 22:21:44