Javascript Get Child Element by Name

前端 未结 1 1698
深忆病人
深忆病人 2021-01-14 13:40

I\'m passing a var el into a function. el contains previously grabbed element (using getElementById) and when I console.log el in the

相关标签:
1条回答
  • 2021-01-14 14:28

    The getElementsByName() API is at the document object level. It's not an HTMLElement method.

    You could use querySelectorAll() instead:

    var fnames = el.querySelectorAll('[name=fname]');
    

    It's not supported in older browsers however.

    0 讨论(0)
提交回复
热议问题