Thanks for your attention and time.
I’m modifying an existing JavaScript but can’t understand a line of code. Please help me understanding this line:
rowArray[i].value = rows[i].getElementsByTagName('td')[sortOn].firstChild.nodeValue;
I am clear till .getElementsByTagName('td'), sortOn is being passed in this function as a parameter. But I couldn’t understand [sortOn].firstChild.nodeValue;
Please guide me,
thanks
rows[i].getElementsByTagName('td')will get alltdelements that are children ofrows[i]. The[sortOn]part selects thetdwhose index is specified by thesortOnparameter. The.firstChild.nodeValuegets the text contained in the first element within thattd.Update: In the DOM, elements such as
<td>can only contain other child elements, but they don’t have any text property. The text itself is contained in a special “text node” that is a child of the<td>node. This is why you use.firstChildto obtain the text node, then use.nodeValueto get the text contained in that node.