Astounded this question didn't show up in the related questions list. There's some similar stuff, but I'd like to know:
string s = "<p>Cats</p><div id='fishbiscuits'>myValue</div>";
I want to use JQuery to get myValue.
How can I do this?
Use the jQuery function to create the objects and then you can use it like you would any other collection of elements. Any of these should work just fine:
// 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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With