Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to parse returned page html with jQuery.get()

Tags:

jquery

I was until recently using $.load() to get a specific piece of another page and load it into the current one, but as the user initiates those requests they can queue up and I found myself needing a way to abort them lest click-happy users break my page.

This led me to $.get() which works great and lets me abort the request if another is launched before the first returns, but now I need to parse the returned html (it's an entire page with doc-type and head elements) and only get one div from it.

How do I achieve this?

like image 373
totallyNotLizards Avatar asked Sep 07 '11 08:09

totallyNotLizards


1 Answers

This should work:

$.get('ajax/test.html', function(data) {
    var my_div = $('#my_div', $(data));
});
like image 69
binarious Avatar answered Sep 23 '22 04:09

binarious