I am using javascript and have dynamically added 9 divs to the document. So now I have 9 divs and each div has a data-number. The data-numbers start at 9 for the first div and end at 17 for the last div. Is there a way I can target the div and return the actual data-number assigned to the div? The reason I want to do this is to style the div based on if its data number is less than, greater than, or equal to an arrays index.
var businessHours = ["9AM" , "10AM" , "11AM" , "12PM" , "1PM" , "2PM" , "3PM" , "4PM" , "5PM"];
var businessIndex = [9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17];
function createTimeblock() {
for (var i = 0; i < businessHours.length; i++) {
var mainDiv =`<div class="row border my-2 mx-1 time-block block${businessIndex[i]}" "data-number=${businessIndex[i]}">` +
`<p class="time-hour0 col-md-1">${businessHours[i]}</p>` +
`<div class="displayTodo col-md-9">` +
`<div class="storedTodo"></div>` +
`<textarea class="plan-here"></textarea>` +
`</div>` +
`<div class="col-md-2">` +
`<button class="col-md-5 clearBtn ml-1"><i class="fas fa-check"></i></button>` +
`<button class="col-md-5 saveBtn"><i class="fas fa-save"></i></button>` +
`</div>`;
$('main').append(mainDiv);
}
}
console.log(HERE IS WHERE I WOULD LIKE TO REUTRN A DIVS DATA-NUMBER)