Add meta-tag domProxy
This commit is contained in:
parent
0a80d860df
commit
8876dcfa68
1 changed files with 13 additions and 0 deletions
13
domProxy.js
13
domProxy.js
|
@ -59,3 +59,16 @@ export const domArray = (methods, extra) => {
|
|||
return new Proxy(element, traps)
|
||||
}
|
||||
}
|
||||
|
||||
export const meta = (element=document.head) => new Proxy(element, {
|
||||
get: (target, name) => target.querySelector(`meta[name="${name}"]`)?.content,
|
||||
set: (target, name, value) => {
|
||||
let meta = target.querySelector(`meta[name="${name}"]`)
|
||||
if (!meta) {
|
||||
meta = document.createElement("meta")
|
||||
meta.name = name
|
||||
target.append(meta)
|
||||
}
|
||||
meta.content = value
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue