Some attributes are directly accessible as properties of the element (e.g. alt, href, id, title and value).
document.querySelector("a").href = "#top";
Other attributes, including data-attributes can be set as follows:
document.querySelector("a").setAttribute("...