getElementsByClassName not working on parsed html data in greasemonkey
开发者_JS百科var xhReq = new XMLHttpRequest(); xhReq.open("GET", linksRaw, false); xhReq.send(null); var serverResponse = xhReq.responseText; var tempDiv = document.createElement('div'); tempDiv.innerHTML = serverResponse.replace(//g, ''); var plzWork = tempDiv.getElementsByClassName('organizationID').innerHTML; console.log(plzWork);
The value of 'plzWork' :-) which is logged to the firebug console is always 'undefined' while the link code is
<a class="organisationID" href="orglists.htm">Partner Organisations</a>
I'm writing this script in the latest versions of Greasemonkey and FF 3.6
Thanks
I hate to point out the piddling little detail because I don't have any other idea why it wouldn't work, but do you really use "organizationID" with a Z when the classname has "organisationID" with an S?
tempDiv.getElementsByClassName('organizationID')
returns a collection, not a single element.
tempDiv.getElementsByClassName('organizationID').innerHtml
then is illegal. Maybe you mean:
tempDiv.getElementsByClassName('organizationID')[0].innerHtml
精彩评论