views:

127

answers:

2

Hi my code is as such

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(/<script(.|\s)*?\/script>/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

+2  A: 

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?

Hellion
+1  A: 

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

Coronatus