I want to perform the document.getElementById() method on the String object.
String.prototype.getElementById = document.getElementById;
test = new String('<p id="para1">Irgendein Text</p>');
console.log(test.getElementById("para1"))
The above attempt returns: Uncaught TypeError: Illegal invocation
Is there a way to perform the getElementByID method on a string?
Edit:
Thanks works like a charm:
var test = (new DOMParser()).parseFromString('<dummy/>', 'text/xml');
test.getElementsByTagName('dummy')[0].innerHTML = '<p id="para1">Irgendein Text</p>';
console.log(doc.getElementById('para1'));
Returns <p id="para1">Irgendein Text</p>