# 4. getAttrubute 擷取屬性內容 - 與 setAttribute 不太一樣的功能: 1. 承上篇,如果是要擷取內容的話,該如何執行? 2. 宣告一個變數: getdata,指定內容到 .titleClass a ,href ``` // 假設我們要撈取 .titleClass 的 a , herf: var getdata = document.querySelector('.titleClass a'); getdata.getAttribute('href'); console.log(getdata); ``` 3. 再透過 getAttribute 的方式去撈取 href 屬性 4. 再透過 `console.log` 的方式來得知我們撈取到了什麼樣的內容: ``` <a href="https://www.cpbl.com.tw/">title</a> ``` ###### tags: `JavaScript - DOM 元素`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up