问题
I have several buttons on the Google Apps Script HTML Service form in Google Sheets (I use Materialize framework). One was written and the rest were cloned from it.
Need to get an array of all that buttons, but I failed. It had to show 3 elements in an array, but it shows 1.
This is the original button which I cloned:
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<div class="input-field col s2.5">
<!--this is the BUTTON -->
<a class="buttonClass waves-effect waves-light btn-small #039be5 light-blue darken-1" style="float: right;" id="btnrow"><i class="material-icons right">send</i>Ввести</a>
</div>
I am trying to get buttons by class (as the ids are different):
var buttons = document.getElementsByClassName('buttonClass').length;
I am doing this to get the id or position of the button that were clicked.
Please let me know if you need me to provide more code. Thanks.
Here's how I cloned elements:
//loop stat names (data from backend)
for (var i = 0; i < stats.statStats.length; i++) {
var statName = stats.statStats[i]
var statNumber = stats.statNumbers[i]
//cloning the original row with all elements
var clonedRow = statRow.cloneNode(true)
//setting unique ID to whole row
var rowId = clonedRow.id = "statsample" + i
//setting unique ID to stat div
var clonedStatID = motherDiv.getElementsByClassName("statClass")[0].id = "statName" + statNumber
//assing stat names
var statHtml = document.getElementById(clonedStatID).innerHTML = statNumber + ". " + statName;
motherDiv.insertBefore(clonedRow, motherDiv.children[0]);
}
来源:https://stackoverflow.com/questions/56798076/cannot-get-an-array-of-all-buttons-from-a-form