amitabhaghosh197
10/8/2015 - 10:52 AM

Javascript get ID of a child element

Javascript get ID of a child element

<html>
<body>
<div id="oInput">
    <input id="1" type="text">
    <input id="2" type="text">
    <input id="3" type="text">
    <input id="4" type="text">
    <input id="5" type="text">
</div>
<script type="text/javascript">
    var oInput = document.getElementById('oInput'),
            oChild;
    for(i = 0; i < oInput.childNodes.length; i++){
        oChild = oInput.childNodes[i];
        if(oChild.nodeName == 'INPUT'){
            alert(oChild.id);
        }
    }
</script>
</body>
</html>