jQuery .find() on data from .ajax() call is returning "[object Object]" instead of div

Viewed 184201

Trying to find div element with id="result" in returned data from .ajax() using .find(). Unfortunately, alert(result) doesn't return div#result.

Here is my code:

$.ajax({
    url: url, 
    cache: false,
    success: function(response) {
        result = $(response).find("#result");
        alert(response); // works as expected (returns all html)
        alert(result); // returns [object Object]
    }
});
17 Answers

try if( $(response).filter('#result').length ) // do something

To view the content in alert use:

alert( $(response).find("#result").html() );

Related