Phantomotap answered your questions already, but I guess I could explain the snippet line by line, in case it might help others.
This is the preferred form in Javascript for initializing a variable to an empty array. (Similarly, it is recommended to use just curly braces instead of new Object() to create a new object.)
We will be adding each new found data entry as a new Object to this array.
Code:
var element = document.getElementsByClassName("name");
The getElementsByClassName returns a HTMLCollection of the elements that have all the given class names. Using .item() is not required, as a HTMLCollection exposes the elements directly by index.
Code:
for (i = 0; i < element.length; i++) {
The HTMLCollection exposes the number elements in the read-only .length property. This for loop therefore goes through all elements in the HTMLCollection, in order.
Code:
dataset[i] = { row: element[i].parentNode,
text: String(element[i].textContent).toLowerCase(),
target: element[i].parentNode.querySelector("select") };
Here we construct a new Object, with properties
.row
referring to the parent of the element whose class was 'name'
.text
referring to the text content, converted to lower case, of the element whose class was 'name', and
.target
referring to the select element related to this entry -- specifically, to the first 'select' descendant starting at the element pointed to by the .row property -- or null if no such element exists.
.querySelector() method was a new one to me, and I like it.
The object initializer syntax is explained in MDN here.
Code:
if (dataset[i].target !== null)
dataset[i].target.addEventListener("focus", self.select_focused);
If we have a row that does not have a select element, the .target property will be null.
If there is a non-null .target, this installs the self.select_focused function as the focus handler for that element.
The intention is that it would auto-open the drop-down list for that member. The function receives a FocusEvent as a parameter, with its .target property specifying the element.
Unfortunately, Firefox 37 at least does not support any way of doing this from Javascript. It is a known woe. The number of dropdown-related bugs in Firefox is so large, I don't think it's going to be addressed anytime soon, though.
For Chrome, synthesizing a mousedown MouseEvent to the target member should work, I've read.