Look at the rendered HTML - the
id
attribute is not going to be exactly equal to "Editor_status".
Every
id
in an HTML document needs to be unique. Your label is inside a data-bound control. There could be hundreds of copies of the label in the page, one for each row of your grid. So ASP.NET automatically turns the server-side ID into a unique client ID when it renders the page.
You'll need to find another way to identify your control from Javascript - for example, by adding another entry in the CssClass list and using
document.getElementsByClassName[
^].
<asp:Label ID="Editor_status" runat="server" Text='<%# Eval("Editor_status") %>' BackColor="SkyBlue" Font-Size="14px" CssClass="badge badge-pill hvr-grow badge-success -js-editor-status" />
$(function(){
var labels = document.getElementsByClassName("-js-editor-status");
...
});
But you also have another problem: the
alert
is inside a Javascript function which you never call. You'll need to fix that if you want the alert to appear.
$(function(){
var labels = document.getElementsByClassName("-js-editor-status");
for (var index = 0; index < labels.length; index++) {
var label = labels[index];
if (label.innerText === "Available") {
alert("Row " + index + ": Available");
}
else {
alert("Row " + index + ": Not available");
}
}
});