Search code examples
javascripthtmlgoogle-chromeinternet-explorertelerik

TypeError: Failed to execute 'item' on 'HTMLCollection': 1 argument required, but only 0


I'm doing cross browser javascript and the line of javascript below works fine in IE11 but doesn't work in Chrome.

selectedItem._element.childNodes[0].getElementsByTagName('input').item().checked;

The error message I get is: TypeError: Failed to execute 'item' on 'HTMLCollection': 1 argument required, but only 0


Solution

  • The problem is that you called the item() function with no parameter although you have to pass the index as parameter of the item() function, i.e. for example:

    selectedItem._element.childNodes[0].getElementsByTagName('input').item(0).checked;
    

    is used to get the checked attribute of the first item returned by the getElementsByTagName() function