Last active
January 21, 2023 18:29
-
-
Save amitabhaghosh197/c5cc24d367d32d2ec57c to your computer and use it in GitHub Desktop.
Javascript get ID of a child element #javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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