-1

I was working to change the label of the button with javascript. The button is using a class but not ID. what js method will applicable?

I tried through getElementsByClassName but this not worked

HTML:

<button type="button" class="window_open">Submit</button>

JS Code:

var status="Newlabel";
document.getElementsByClassName("window_open").innerHTML=status;

I expect the output of Newlabel but there is no result

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79

1 Answers1

1

Since getElementsByClassName returns an array-like object, you need the first item [0]:

var status = "Newlabel";
document.getElementsByClassName("window_open")[0].innerHTML = status;
<button type="button" class="window_open">Submit</button>
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79