michaellindahl
michaellindahl

Reputation: 2052

Odd JavaScript getElementsByName undefined error

Okay, I've seriously got to be missing something or I'm crazy. Here's the code I'm having an issue with, it is inside an onchange event:

console.log( (this.parentNode.parentNode) );
// fine prints the elements

console.log( (this.parentNode.parentNode).getElementsByName('otherposition[]') );
// gives me undefined error

(this.parentNode.parentNode).getElementsByName('otherposition[]')[0].style.opacity = '1';
// same error.

Upvotes: 0

Views: 160

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117324

getElementsByName is a method of document, elements doesn't have such method.

Upvotes: 3

Related Questions