2

if I have a valid html fragment in a variable like so;

var responseText = 'Lorem <span>Ipsum</span>';

How can I find the $("span").html() of that responseText, in other words get the Ipsum?

2 Answers 2

2

Usually, if responseText represented an HTML element, you could have used $(responseText) to parse it. Here, it easiest to create a temporary element, and setting its html:

var dummy = $('<div />').html(responseText);
var text = dummy.find('span').text();

Working example: http://jsbin.com/ebeju4

Sign up to request clarification or add additional context in comments.

Comments

1
$('<div/>').html(responseText).find('span').html();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.