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

前端 未结 17 1281
一生所求
一生所求 2020-12-07 22:05

Trying to find div element with id=\"result\" in returned data from .ajax() using .find(). Unfortunately, alert(res

17条回答
  •  感情败类
    2020-12-07 23:02

    To answer your question specifically, it seems to be working correctly. You said that it returns [object Object], which is what jQuery will return with the find("#result") method. It returns a jQuery element that matches the find query.

    Try getting an attribute of that object, like result.attr("id") - it should return result.


    In general, this answer depends on whether or not #result is the top level element.

    If #result is the top level element,

    
    
    Text

    find() will not work. Instead, use filter():

    var $result = $(response).filter('#result');
    

    If #result is not the top level element,

    
    
    Text

    find() will work:

    var $result = $(response).find('#result');
    

提交回复
热议问题