Change Element Style
Changes the inline style of an element.
- dom
- style
Install
npx shadcn@latest add https://quicksnip.dev/r/change-element-style.jsonThis snippet is not verified yet. Review it before use, or help verify it.
Code
const changeElementStyle = (element, styleObj) => {
Object.entries(styleObj).forEach(([property, value]) => {
element.style[property] = value;
});
};Usage
const element = document.querySelector('.my-element');
changeElementStyle(element, { color: 'red', backgroundColor: 'yellow' });