使用JQuery解析包含html的字符串

Nib*_*Pig 4 html jquery

令人震惊的是这个问题没有出现在相关问题列表中.有类似的东西,但我想知道:

string s = "<p>Cats</p><div id='fishbiscuits'>myValue</div>";
Run Code Online (Sandbox Code Playgroud)

我想用JQuery来获取myValue.

我怎样才能做到这一点?

And*_*y E 6

使用jQuery函数创建对象,然后就像使用任何其他元素集一样使用它.任何这些应该工作得很好:

// Using filter()
$(s).filter("#fishbiscuits").text();

// Wrapping with a div and using find()
$('<div>' + s + '</div>').find("#fishbiscuits").text();

// Wrapping with a div and using selector context
$('#fishbiscuits', '<div>' + s + '</div>').text();

// Creating a div, setting the html and then using find
$('<div>').html(s).find("#fishbiscuits").text();
Run Code Online (Sandbox Code Playgroud)