JakeParis
JakeParis

Reputation: 11210

not able to manipulate data returned from $.ajax

I need to remove an element with the class .connectNow from the data returned with the following ajax call:

$.ajax({
    type: 'get',
    url: pages[i] +'.php',
    data: 'ajax=1',
    success: function(txt) {

        // the following line is not operating as expected
        $(txt).find('.connectNow').remove();
        $('.slide').eq(0).after('<div class="slide">' + txt + '</div>');
        $('.slide').animate({'left':'-=425px'},1500);
    }   
});

I've looked at (and tried) the following, none of which seem to help in my situation, unless I'm implementing them wrong.

Upvotes: 1

Views: 141

Answers (2)

Explosion Pills
Explosion Pills

Reputation: 191729

A working version (using fake input xml):

http://jsfiddle.net/jMQX5/1

Some of the seemingly strange choices made are explained with inline comments.

Upvotes: 1

nbrooks
nbrooks

Reputation: 18233

You should set the data type of your returned ajax to be html (it may be defaulting to text, though jQuery is supposed to guess what it is).

If that doesn't work though here is a little hack which may help you

txt = $('<div/>').append(txt).find('.connectNow').remove().end().html();

Upvotes: 0

Related Questions