Daniele
Daniele

Reputation: 847

How to manipulate html loaded with jQuery.ajax()

I have:

        $.ajax({ type: 'POST',   
             url: myLink,   
             async: false,
             dataType: 'html',
             success : function(page) {

                 var fragment = page.find('#myId').html();
                                 ...

                                 // I'll append my fragment to #somewhere


        });

this is not working, console says page.find is not a function.

what am I doing wrong?

Upvotes: 0

Views: 310

Answers (1)

jondavidjohn
jondavidjohn

Reputation: 62392

Try this...

var fragment = $(page).find('#myId').html();

page itself is just a string containing the html you requested... So you have to first create a jQuery object to call jQuery methods on.

Upvotes: 3

Related Questions