{"id":25495613,"url":"https://github.com/hekigan/dom-create-element-query-selector","last_synced_at":"2025-04-10T02:41:58.029Z","repository":{"id":57214636,"uuid":"80430057","full_name":"hekigan/dom-create-element-query-selector","owner":"hekigan","description":"A utility function to create DOM elements with CSS selector-like syntax","archived":false,"fork":false,"pushed_at":"2017-10-31T06:45:56.000Z","size":51,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T04:12:03.152Z","etag":null,"topics":["create-element","css-selector","dom","dom-elements"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hekigan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-30T14:46:45.000Z","updated_at":"2024-05-23T02:44:14.000Z","dependencies_parsed_at":"2022-08-26T13:41:27.164Z","dependency_job_id":null,"html_url":"https://github.com/hekigan/dom-create-element-query-selector","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hekigan%2Fdom-create-element-query-selector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hekigan%2Fdom-create-element-query-selector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hekigan%2Fdom-create-element-query-selector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hekigan%2Fdom-create-element-query-selector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hekigan","download_url":"https://codeload.github.com/hekigan/dom-create-element-query-selector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248144966,"owners_count":21055019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["create-element","css-selector","dom","dom-elements"],"created_at":"2025-02-19T00:37:42.128Z","updated_at":"2025-04-10T02:41:58.009Z","avatar_url":"https://github.com/hekigan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dom-create-element-query-selector\n\n![Node](https://img.shields.io/node/v/dom-create-element-query-selector.svg?style=flat-square)\n[![NPM](https://img.shields.io/npm/v/dom-create-element-query-selector.svg?style=flat-square)](https://www.npmjs.com/package/dom-create-element-query-selector)\n[![Travis](https://img.shields.io/travis/hekigan/dom-create-element-query-selector/master.svg?style=flat-square)](https://travis-ci.org/hekigan/dom-create-element-query-selector)\n[![Coverage Status](https://coveralls.io/repos/github/hekigan/dom-create-element-query-selector/badge.svg?branch=master)](https://coveralls.io/github/hekigan/dom-create-element-query-selector?branch=master)\n\n\u003e A utility function to create DOM elements with CSS selector-like syntax\n\n### Description\n\nAs I had to use vanilla Javascript for a project, I got upset with how verbose it was to create DOM elements.\n\nI use the same css-selector-like syntax as `document.querySelector()` to create the new Nodes in a more compact, simple and readable way.\n\nThere are no dependencies and multiple versions are available (es5, es6, UMD). See the BUILD section below for more information. \n\n### Usage\n\n#### Basic\n\nThe simplest example add an empty `div` tag to the document's `body`.\n```js\nimport createElement from 'dom-create-element-query-selector';\n\nconst body = document.querySelector('body');\nbody.appendChild(createElement());\n```\n\n#### Other usages\n```js\nimport createElement from 'dom-create-element-query-selector';\n\nlet elt = null;\n\n// some examples\n\nelt = createElement(); // \u003cdiv\u003e\u003c/div\u003e\n\n// create a span node with an id\nelt = createElement('span#my-id'); // \u003cspan id=\"my-id\"\u003e\u003c/span\u003e\n\n// add class\nelt = createElement('span.my-class'); // \u003cspan class=\"my-class\"\u003e\u003c/span\u003e\n\n// add id and class\nelt = createElement('span#my-id.my-class'); // \u003cspan id=\"my-id\" class=\"my-class\"\u003e\u003c/span\u003e\n\n// add class and attributes\nelt = createElement('a[href=#].link'); // \u003ca class=\"link\" href=\"#\"\u003e\u003c/a\u003e\n\n// add content to the new element (text \u0026 other nodes)\nelt = createElement('div',\n    'paragraphs',\n    createElement('p', 'paragraph 1'),\n    createElement('p', 'paragraph 2')\n);\n// \u003cdiv\u003e\n//  paragraphs\n//  \u003cp\u003eparagraph 1\u003c/p\u003e\n//  \u003cp\u003eparagraph 2\u003c/p\u003e\n// \u003c/div\u003e\n\n// add the generated element to the DOM\ndocument.querySelector('body').appendChild(elt);\n\n```\n\n### Installation\n\nInstall via [yarn](https://github.com/yarnpkg/yarn)\n\n\tyarn add dom-create-element-query-selector (--dev)\n\nor npm\n\n\tnpm install dom-create-element-query-selector (--save-dev)\n\n\n### Examples\n\nSee [`example`](example/script.js) folder or the [runkit](https://runkit.com/hekigan/dom-create-element-query-selector) example.\n\n### Builds\n\nIf you don't use a package manager, you can [access `dom-create-element-query-selector` via unpkg (CDN)](https://unpkg.com/dom-create-element-query-selector/), download the source, or point your package manager to the url.\n\n`dom-create-element-query-selector` is compiled as a collection of [CommonJS](http://webpack.github.io/docs/commonjs.html) modules \u0026 [ES2015 modules](http://www.2ality.com/2014/09/es6-modules-final.html) for bundlers that support the `jsnext:main` or `module` field in package.json (Rollup, Webpack 2)\n\nThe `dom-create-element-query-selector` package includes precompiled production and development [UMD](https://github.com/umdjs/umd) builds in the [`dist` folder](https://unpkg.com/dom-create-element-query-selector/dist/). They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. You can drop a UMD build as a [`\u003cscript\u003e` tag](https://unpkg.com/dom-create-element-query-selector) on your page. The UMD builds make `dom-create-element-query-selector` available as a `window.createElement` global variable.\n\n### License\n\nThe code is available under the [MIT](LICENSE) license.\n\n### Contributing\n\nWe are open to contributions, see [CONTRIBUTING.md](CONTRIBUTING.md) for more info.\n\n### Misc\n\nThis module was created using [generator-module-boilerplate](https://github.com/duivvv/generator-module-boilerplate).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhekigan%2Fdom-create-element-query-selector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhekigan%2Fdom-create-element-query-selector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhekigan%2Fdom-create-element-query-selector/lists"}