create-element-helper

A helper for `document.createElement()` that can be loaded into a script with `require`.

2025/12/18のページです。最新版はこちら

このスクリプトは単体で利用できません。右のようなメタデータを含むスクリプトから、ライブラリとして読み込まれます: // @require https://update.greasyfork.org/scripts/559372/1716505/create-element-helper.js

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
function tag(name) {
  return {
    elem: document.createElement(name),

    id: function (value) {
      this.elem.setAttribute('id', value)
      return this
    },

    attr: function (name, value) {
      this.elem.setAttribute(name, value)
      return this
    },

    style: function (name, value) {
      this.elem.style[name] = value
      return this
    },

    cssClass: function (value) {
      this.elem.classList.add(value)
      return this
    },

    checked: function (value) {
      this.elem.checked = !!value
      return this
    },

    text: function (content) {
      this.elem.textContent = content
      return this
    },

    on: function (event, handler, options = {}) {
      this.elem.addEventListener(event, handler, options)
      return this
    },

    append: function (child) {
      this.elem.appendChild(child.elem || child)
      return this
    },

    create: function () {
      return this.elem
    },
  }
}