setCss

说明

设置单个DOM样式

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/dom/setCss

用法

setCss.test.ts
import { setCss } from "../../utility/dom/setCss";

describe('setCss', () => {
  test('setCss should receive a DOM object and CSS Rule options, add rules to DOM.', () => {
    document.body.innerHTML = `
      <div id="app">app</div>
    `;

    setCss(
      document.getElementById('app') as HTMLElement,
      {
        color: 'red',
        'font-size': 25,
      },
    );

    expect((document.getElementById('app') as HTMLElement).getAttribute('style')).toBe('color: red; font-size: 25;');

  });
});

最后更新于