Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery in a HTML formatted string

I have some AJAX call like this:

$.ajax({
    type: 'GET',
    url: <some url>,
    dataType: 'html',
    success: function(html){
        // do some jQuery on the response html
        // like this: $('#someDIV').text();
    }
});

The response html likes this:

<html>
<head>
    <!-- header things -->
</head>
    <div id="someDIV">
        content
    <div>
</html>

Can I do the query on that response html without append the code to current page?

like image 842
Tin Nguyen Avatar asked Mar 13 '26 14:03

Tin Nguyen


1 Answers

Simply wrap by jQuery and do the rest.

var $html = $(html);
like image 130
Pranav C Balan Avatar answered Mar 16 '26 02:03

Pranav C Balan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!