I have a JavaScript string with HTML content inside it.
e.g.
var HTMLtext = 'text <div id="test-div-1">this is <b>just</b> a div</div><div id="test-div-2">this is <b>just</b> another div</div> more filler text';
I am looking to get the innerHTML from the first div element within this string. When I try using:
var testDiv1 = HTMLtext.getElementByID("test-div-1");
I get the error
HTMLtext.getElementByID is not a function at window.onload
Are there any workarounds without putting HTMLtext in a temporary container?
HTMLtextvariable is a string not html element. What you are trying to do is same as if you would try'this is some text.getElementById('id')`. If you want to get the div with id you would have to do som regex string search.. What exactly are you trying to acomplish?