Let me give few examples around it. Below is the sample HTML and script. Code is very simple and self explanatory. However, to make it more clear, I have also put comments around the same. Also, while writing the same, you can see below screenshot, editor is helping at every point. I am using webstorm here. You can use any of your favorite editors.
Below is the finished snippet of the same.
With the above change in place, when i simply go ahead and test the same in browser, it will give me below output.
With the above change in place, when I run this functionality, then this will give new improvised output.