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

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

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

17条回答
  •  猫巷女王i
    2020-12-07 22:41

    this is your answer:

    Hello
    World

    The following jQuery Won't work:

    $(data).find('div.test');    
    

    as the divs are top level elements and data isn't an element but a string, to make it work you need to use .filter

    $(data).filter('div.test');    
    

    Another same question: Use Jquery Selectors on $.AJAX loaded HTML?

提交回复
热议问题