element.setAttribute(attributeName, value)
<input type="password" value="test">
<button type="button">パスワードを表示</button>
const elem = document.querySelector("input");
const button = document.querySelector("button");

button.addEventListener("click", () => { // ボタンのクリックイベント
    /* ボタンをクリックすると、
       input要素のtype属性の値がpasswordからtextに変更されます。 */
    elem.setAttribute("type", "text");
});
実際の適用例 「パスワードを表示」ボタンをクリックしてみてください!
<input type="text">
<button type="button">testを入力する</button>
const elem = document.querySelector("input");
const button = document.querySelector("button");

button.addEventListener("click", () => { // ボタンのクリックイベント
    /* ボタンをクリックすると、
       input要素にvalue属性が追加され、
       値がtestに設定されます。 */
    elem.setAttribute("value", "test");
});
実際の適用例 「testを入力する」ボタンをクリックしてみてください!
const element = document.getElementById("example-id");

// 1つ目の属性を設定
element.setAttribute("alt", "Set your alt");

// 2つ目の属性を設定
element.setAttribute("title", "Set your title");

// 3つ目の属性を設定
element.setAttribute("src", "/images/image.jpg");
<input type="text">
<button type="button">input boxを非表示にする</button>
const elem = document.querySelector("input");
const button = document.querySelector("button");

button.addEventListener("click", () => { // ボタンのクリックイベント
    /* ボタンをクリックすると、
       input要素にhidden属性を追加します。
       値は空の文字列("")に設定します。 */
    elem.setAttribute("hidden", "");
});
実際の適用例 「input boxを非表示にする」ボタンをクリックしてみてください!
element.setAttribute("style", "background-color:blue;");
element.style.backgroundColor = "blue";