Function addStyle

  • EN: Add <style> in <head>.

    ZH: 添加样式标签; style: 样式标签内的字符串; id: <style> 标签的 id; 返回: 添加成功/失败

    Example 1: Add the <style> with id, and repeated invoking will update the content instead of adding a new one.

    addStyle(
    `
    body {
    background-color: #333;
    }
    `,
    {
    id: 'test',
    }
    );
    // <style id="test">
    // body {
    // background-color: #333;
    // }
    // </style>

    Example 2: Add the <style> without id, and repeated invoking will add a new one.

    addStyle(
    `
    body {
    background-color: #444;
    }
    `
    );
    // <style>
    // body {
    // background-color: #444;
    // }
    // </style>

    Parameters

    • style: string
    • options: {
          id?: string;
      } = ...
      • Optional id?: string

    Returns boolean