Skip to content

Instantly share code, notes, and snippets.

@amitabhaghosh197
Last active January 21, 2023 18:29
Show Gist options
  • Save amitabhaghosh197/c5cc24d367d32d2ec57c to your computer and use it in GitHub Desktop.
Save amitabhaghosh197/c5cc24d367d32d2ec57c to your computer and use it in GitHub Desktop.
Javascript get ID of a child element #javascript
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment