jQuery.get() and returned html data: how to extract piece of codes?

1k Views Asked by At

Suppose that you can retrieve an HTML page through a call by using the jQuery.get() function, e.g. as follows:

$.get('xxx.php', 
        function(data) {
        //handle data, that is HTML code....
});

Is there any jQuery solution to extract elements (e.g. div, ul and so on) by the data variable?

PS: I don't believe that using load() to load page fragments is a good idea since I want to minimize the number of server requests.

1

There are 1 best solutions below

1
On BEST ANSWER
$.get('xxx.php', 
        function(data) {
        //handle data, that is HTML code....
        var pageDivs = $(data).find('div');
});

Just make the HTML returned a jquery object and you can use any DOM functions normally.