Get all input fields inside div (without JS library)

可紊 提交于 2019-11-30 06:41:49
document.getElementById('mydiv').getElementsByTagName('input')

Try:

var inputs = document.getElementById('mydiv').getElementsByTagName('input');
Vishnu Prasanth G

querySelector and querySelectorAll will fetch the details of what you're expecting easily.

var divElem = document.getElementById("myDiv");
var inputElements = divElem.querySelectorAll("input, select, checkbox, textarea");

It will give all the input, select, textarea elements in array format.

document.getElementById("mydiv").getElementsByTagName("input");

If you are on modern browsers (ie9+) you can take advantage of querySelectorAll‎.

var inputs = document.querySelectorAll‎('#myDiv input');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!