lcplben said:
The problem page ishttp://sellmycalls.com/no-hdrtext.htmland the
problem is at lines 111-137.
The function getColHdrText (line 124) wants to retrieve the column-
header text from the second of three <span>s in the <th>. I thought
that if I only got to the <span>, I could easily access the innerHTML
just as slick as slick. It should be a five-minute task at most, but
I've been working on it for a couple of hours now with no joy.
What am I doing wrong, please?
The relevant code is (you want to post this next time):
/* Line 69 below */
function getElementsByClass ( theClass, node, tag ) {
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
elems = node.getElementsByTagName( tag );
var elemsLen = elems.length;
var pattern = new RegExp("(^|\\s)"+theClass+"(\\s|$)");
for (i = 0, j = 0; i < elemsLen; i++) {
if ( pattern.test(elems
.className) ) {
classElements[j] = elems;
j++;
}
}
return classElements;
}
/* Line 111 below */
/* from this <th>, I want to retrieve the word "Call" from the second
<span>,
the <span class='chtxt'...>Call</span>
<th class="cal_option_symbol" style="color:rgb(204, 0, 51);">
<span class='chimg'><img src='http://www.sellmycalls.com/pics/blu-mins.jpg'
alt='hide column' title='hide column'
onclick="return columnHideShowByImg(this,'Call');"></span>
<span class='chtxt' title="symbol of this call option"
style="font-weight:bold;"
onClick="return selectColumnAsFilter(this);">Call</span>
<span class='chtri'><img src='http://www.sellmycalls.com/pics/asc.jpg'
alt='ascending sort' title='ascending sort'
onclick="return columnToggleSortOrder(this);"></span>
</th>
*/
// enter here with 'col' = the <th> element
function getColHdrText( col ) {
var ch, s;
ch = getElementsByClass( 'chtxt', col, 'SPAN' );
// Firebug tells me here that ch == the 'chtxt' element, so
// I figure I should be able to just retrieve innerHTML from
// that element, right?
s = ch.innerHTML; // but none of these work so I'm
s = ch.innerText; // missing something crucial.
s = ch.textContent; // what is that something?
s = ch.value;
return (s && s != 'undefined') ? s : 'nfg' ;
}
If you have a closer look at the getElementsByClass() function that you are
calling, starting with its name and going on with the loop inside, you can
see that it returns an array of element object references. Therefore, you
are accessing the Array instance instead of the element object. That Array
instance has neither property that you tried to read from.
Firebug indicates that `ch' stores an Array instance reference by displaying
brackets in the console. You must have missed that. You could access the
first element of the array with `ch[0]'.
BTW, the getElementsByClass() function here is error-prone for several
reasons; search the archives for further information and better
alternatives.