Is there a shorter way to write this in JavaScript?
var data = [];
var table = document.getElementById( 'address' );
var rows = table.getElementsByTagName( 'tr' );
for ( var x = 0; x < rows.length; x++ ) {
var td = rows[x].getElementsByTagName( 'td' );
for ( var y = 0; y < td.length; y++ ) {
var input = td[y].getElementsByTagName( 'input' );
for ( var z = 0; z < input.length; z++ ) {
data.push( input[z].id );
}
}
}
element.getElementsByTagName
finds all descendants, not only children, so:
<script type="text/javascript>
var data = [];
var table = document.getElementById( 'address' );
var input = table.getElementsByTagName( 'input' );
for ( var z = 0; z < input.length; z++ ) {
data.push( input[z].id );
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With