There's a similar thread here, but it only deals with parsing Element-only HTML strings.
How to get an HTML element from a string with jQuery
In my case, I have an HTML string combining plain text with element(s).
var str = 'Some text ' +
'<input type="hidden" id="hiddenField" value="3" /> ' +
'<input type="text" id="textField"/>';
I need the following 2 functions, (1) Extract Plain Text from this string, (2) Extract Element by ID.
Examples:
(1) getText(str) => 'Some text ';
(2) getElement(str, id) => jQuery element variable
I was going to split by ID, and then split by <
/>
multiple times, then stitch together different strings, but that doesn't seem elegant, wondering if there are better ways.