Get the text inside <h2> element from an ajax jquery post response Get the text inside <h2> element from an ajax jquery post response ajax ajax

Get the text inside <h2> element from an ajax jquery post response


You can pass HTML to jQuery and use it in the same way as if the element was on the DOM, for example with find():

console.log( $(resultData).find('h2').text() );

If your HTML doesn't have a root element then you can wrap it like so:

resultData = '<div>' + resultData + '</div>';console.log( $(resultData).find('h2').text() );


How about:

$(resultData).find('h2').text()