DOM related method

Method
description
example

new DOMParser() .parseFromString(xx, 'text/html')

透過它來對字串進行解析,進而轉換成 document

const doc = new DOMParser().parseFromString( `<div class="foo bar baz"> Paragraph </div>` ,'text/html');

Node.contains()

return boolean

document.body.contains(node)

<div id="ele" a="s" b="b"></div> let ele = document.getElementById('ele')

Node.getAttributeNames()

return array 抓所有 att name

ele.getAttributeNames()

// ['id', 'a', 'b']

Node.getAttribute('xx')

return string

ele.getAttribute('id')

// ele

Node.tageName

return string

ele.tageName

// DIV

Last updated

Was this helpful?