First of all, always give id if you want to select specific element and make changes to them, that's a good practice. Otherwise you can use css selectors also with querySelector.
I have added the code to update the title using setTimeout()
function just to illustrate the use so you can see it updating. setTimeout()
will update the title after 5 seconds.
If you want to do it on the click of a button check the comments in the below code. to use it inside a function just add the code - let title = document.querySelector("#title"); title.innerHTML="Updated"
inside your function.
You can also use title.textContent="Updated"
instead of title.innerHTML="Updated"
Also, make sure the javascript is added to the end of the body or is set to run only after the entire body is rendered, to avoid "element not found error.
let title = document.querySelector("#title");
setTimeout(()=>{title.innerHTML="Updated"},5000);
//Code to update the title using a button Click
//let btn=document.querySelector("#btnUpdateTitle");
//btn.addEventListener('click',()=>{title.innerHTML="Updated"});
<ul class="properties">
<li>
<label>
<b id="title"> Charge Amount </b>
</label>
</li>
</ul>
<!-- Code to update the title using a button Click -->
<!-- <button id="btnUpdateTitle">Update Title</button> -->
Code for updating the title without giving id to the tag.
let title = document.querySelector("li:nth-Child(2)>label>b");
setTimeout(()=>{title.innerHTML="Updated"},5000);
//Code to update the title using a button Click
//let btn=document.querySelector("li:nth-Child(2)>lable>b");
//btn.addEventListener('click',()=>{title.innerHTML="Updated"});
<ul class="properties">
<li>
<label>
<b id="title"> Charge Amount 1</b>
</label>
</li>
<li>
<label>
<b id="title"> Charge Amount 2 </b>
</label>
</li>
<li>
<label>
<b id="title"> Charge Amount 3 </b>
</label>
</li>
</ul>
<!-- Code to update the title using a button Click -->
<!-- <button id="btnUpdateTitle">Update Title</button> -->