getAttribute method is used to get the value of any attribute in html tag.
Syntax of using getAttribute
element.getAttribute (attributename);
const target = document.querySelector("h1");
// Original attribute
console.log(target.getAttribute("message"))
<h1 message="I am message in h1 tag"></h1>
setAttribute method is used to set the value of any attribute in html tag.
Syntax of using setAttribute
element.setAttribute(attributename, attributevalue);
const target = document.querySelector("h1");
// Original attribute
console.log(target.getAttribute("message"))
// changed attribute
target.setAttribute("message","message attribute changed")
console.log(target.getAttribute("message"))
<h1 message = "this is the title of the page"></h1>https://stackoverflow.com/questions/72569107/use-javascript-to-write-text-into-html-interface#