开发者

How to select elements stored in a string variable?

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?


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜