{"id":17705000,"url":"https://github.com/dwqs/tiny-dom-helpers","last_synced_at":"2025-03-13T08:31:50.457Z","repository":{"id":58228073,"uuid":"99348660","full_name":"dwqs/tiny-dom-helpers","owner":"dwqs","description":":last_quarter_moon_with_face: :new_moon_with_face: :first_quarter_moon_with_face: Tiny dom helpers, supports IE9 +.","archived":false,"fork":false,"pushed_at":"2017-12-05T17:20:06.000Z","size":155,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-26T11:20:18.983Z","etag":null,"topics":["dom","dom-helpers","element"],"latest_commit_sha":null,"homepage":"","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/dwqs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-04T14:04:34.000Z","updated_at":"2023-03-20T05:22:32.000Z","dependencies_parsed_at":"2022-08-31T09:20:23.561Z","dependency_job_id":null,"html_url":"https://github.com/dwqs/tiny-dom-helpers","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Ftiny-dom-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Ftiny-dom-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Ftiny-dom-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Ftiny-dom-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwqs","download_url":"https://codeload.github.com/dwqs/tiny-dom-helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243369886,"owners_count":20280095,"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":["dom","dom-helpers","element"],"created_at":"2024-10-24T22:05:49.996Z","updated_at":"2025-03-13T08:31:50.065Z","avatar_url":"https://github.com/dwqs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com) [![build pass](https://api.travis-ci.org/dwqs/tiny-dom-helpers.svg?branch=master)](https://travis-ci.org/dwqs/tiny-dom-helpers) ![npm-version](https://img.shields.io/npm/v/tiny-dom-helpers.svg) ![license](https://img.shields.io/npm/l/tiny-dom-helpers.svg) ![bower-license](https://img.shields.io/bower/l/tiny-dom-helpers.svg)\n\n# tiny-dom-helpers\nTiny dom helpers, only supports IE9+.\n\n## Installation\nInstall the pkg with npm:\n```\nnpm install tiny-dom-helpers --save\n```\nor yarn\n```\nyarn add tiny-dom-helpers\n```\nor bower\n```\nbower install tiny-dom-helpers\n```\nYou can also hot-link the CDN version: https://unpkg.com/tiny-dom-helpers/dist/index.js, `tinyDOM` is exposed to `window` object.\n\n## Usage\nIf we have some dom elements as follows:\n\n```html\n\u003cbody\u003e\n    \u003cdiv id=\"div\" style=\"position: relative\"\u003e\n        \u003cp\u003e\n            \u003cdiv id=\"test\"\u003e33333\u003c/div\u003e\n            11111\n            \u003cspan id='span' class=\"test1 test2\"\u003eHello\u003c/span\u003e \n            000\n            \u003cspan id=\"span2\"\u003e22222\u003c/span\u003e    \n        \u003c/p\u003e    \n    \u003c/div\u003e \n\u003c/body\u003e    \n```\n\n```\nimport { css, offset, createTinyDOM } from 'tiny-dom-helpers';\n\n// get dom element\nlet span = document.getElementById('span');\nlet s = createTinyDOM(span);\n\ns.toArray(); \n// =\u003e ['test1', 'test2']\n\ns.addClass('tt t2')\ns.toArray(); \n// =\u003e ['test1', 'test2', 'tt', 't2']\n\ns.removeClass('test2 t2')\n// or s.removeClass(/2/);\ns.toArray(); \n// =\u003e ['test1', 'tt']\n\ns.toggle('rr')\ns.toggle('tt')\ns.toArray(); \n// =\u003e ['test1', 'rr']\n\ns.hasClass('rr')\n// =\u003e true\n\ns.next();\n// =\u003e the next element of span, eg: span#test\n\ns.parent();\n// =\u003e the parent element of span, eg: p\n\ns.offsetParent();\n// =\u003e the closest positioned element of span, eg: div#div\n\ns.previous();\n// =\u003e the previous element of span, eg: div#div2\n\ncss(span, 'width', null)\n// =\u003e span's width, eg: 20px\n\ncss(span, 'font-size', \":after\")\n// =\u003e eg: 10px\n\noffset(span)\n// =\u003e the position of span relative to ducument. eg: {top: 100, left: 100, width: 10, height: 20}\n```\n\n## API\n#### css(node, properyty, pseudoEle = null)\nReturn the css properyty of node or node's pseudo-element.\n\n#### offset(node)\nReturn the size and position of the element's bounding box, relative to the document.\n\n#### createTinyDOM(node)\nReturn an instance of TinyDOM.\n\n#### .toArray()\nReturn an array of the class names on the element.\n\n#### .hasClass(class)\nCheck whether the element has the given class and return a boolean.\n\n#### .addClass(class)\nAdd the given class in the class list if it doesn't exist and return the instance. \n\n#### .removeClass(class|regexp)\nRemove the given class in the class list if it's already exist and return the instance.\n\n#### .toggle(class)\nToggle the given class in the class list and return the instance.\n\n#### .replaceClass(oldClass, newClass)\nReplaces an existing class with a new class and return the instance.\n\n#### .text(text = '')\nText's getter/setter of the element and return the text. \n\n#### .attr(prop, value = '')\nAttributes' getter/setter of the element and return the prop value. \n\n#### .getNodeName()\nReturn the node name of the element.\n\n#### .width(pseduo-element=null)\nReturn the width of the element or it's pseudo-elements.\n\n#### .height(pseduo-element=null)\nReturn the height of the element or it's pseudo-elements.\n\n#### .rect()\nReturn the size and position of the element's bounding box, relative to the viewport.\n\n#### .offsetParent()\nReturn the object which is the closest positioned containing element.\n\n#### .positions()\nReturn the size and position of the element's bounding box, relative to the offsetParent.\n\n#### .previous()\nReturn the previous HTMLElment of the element.\n\n#### .next()\nReturn the next HTMLElment of the element.\n\n#### .parent()\nReturn the parent HTMLElment of the element.\n\n#### .contains(node)\nCheck whether the given node is the element's children and return a boolean.\n\n### LICENSE\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwqs%2Ftiny-dom-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwqs%2Ftiny-dom-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwqs%2Ftiny-dom-helpers/lists"}