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/1716605/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(v) {
      this.elem.setAttribute('id', v)
      return this
    },

    attr: function(k, v) {
      this.elem.setAttribute(k, v)
      return this
    },

    style: function(k, v) {
      this.elem.style[k] = v
      return this
    },

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

    href: function(v) {
      this.elem.setAttribute('href', v)
      return this
    },

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

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

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

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

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

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

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