例 ❶ (答案:標題)
const main = document.querySelector(".main");
main.innerHTML = `<h1 class="header">標題</h1>`
例 ❷ (.denny12)
const list = document.querySelector(".list");
let mylink = "https://crypto.cnyes.com/BTC/3y"
list.innerHTML = `<li class="list"><a href="${mylink}">denny12</a></li>`
例 ❶
<a href="https://www.yahoo.com" class="red"><span>連結</span></a>
const mylink = document.querySelector("a");
console.log(mylink.getAttribute("href"));
console.log(mylink.getAttribute("class"));
例 ❷
<input type="text" class="txt" value="你好嗎">
const txt = document.querySelector(".txt");
console.log(txt.value);
const el = document.querySelector('.a')
textContent
(圖片來源:六角學院)
innerHtml
(圖片來源:六角學院)
(圖片來源:六角學院)