So, I've got a nifty little recursive function that runs through a select box and all it's children looking for the selected element and removes it, if the parent element is empty then it removes that as well. However, the W3C decided when passing DOM that there are 12, count 'em, 12 different node types.
So my function works perfectly well until it tries to do it's job and crawls across an option
node, which as defined by DOM has a nodeType
of 3 (text node). However, the brilliant engineers decided that TEXT NODES should have child nodes which mirror the text attribute, ie.,
<option id="s3">Text is here</option>
DOM:
element.id = "s3"
element.text = "Text is here"
element.childNodes = ["Text is here"]
[0]
nodeType = 3
nodeValue = "Text is here"
This, of course, boggles my mind. So checking nodes for the number of child nodes results in a false positive on option
type nodes causing the function to incorrectly call and put itself into an infinite loop crawling the same node.
I've fixed it by kludging the crap out of it when checking the nodeType as well as the node length but.. wow, how on earth is that even logical?