Use getAttribute() and setAttribute() to work with HTML attributes.
const link = document.querySelector("a");
console.log(link.getAttribute("href"));
link.setAttribute("href", "https://example.com");
link.setAttribute("target", "_blank");
Some attributes like id, className, and href also have direct properties.