Rabbitzzc / operate-css

Insert CSS into head, or insert CSS attributes into any element.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

operate-css

Insert CSS into head, or insert CSS attributes into any element. npm -> operate-css

usage

install

yarn add dom
npm install dom 

import dom from 'dom'

css()

// css({ el, styles }: { el: { style: { [x: string]: any } }; styles: { [x: string]: any } })
const el = document.getElementById('#dom')
const styles = {
    color: 'red',
    backgroundColor: 'lightblue'
}
dom.css(el, styles)

getStyleValue()

// getStyleValue({ el, attr }: { el: HTMLElement; attr: string; })
const el = document.getElementById('#dom')
dom.getStyleValue(el, 'backgroundColor')

insertCSS()

// insertCSS(css: string, options: { target?: any; prepend?: boolean })
// insert a string of css into the <head>
const css = 'body { background:blue; }'
const options = {
    target: 'head', // element
    prepend: true // true ?  'prepend' : 'append'
}
dom.insertCSS(css, options)

About

Insert CSS into head, or insert CSS attributes into any element.

License:MIT License


Languages

Language:TypeScript 100.0%